|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub limonet()
Dim Cn As Object, StrSQL$, S$, IIF2$, Arr As Variant, i%
Set Cn = CreateObject("Adodb.Connection")
S$ = "IIF(语文 Is Null,'语文',Null) As 语文,IIF(数学 Is Null,'数学',Null) As 数学,IIF(英语 Is Null,'英语',Null) As 英语," _
& "IIF(政治 Is Null,'政治',Null) As 政治,IIF(历史 Is Null,'历史',Null) As 历史,IIF(地理 Is Null,'地理',Null) As 地理," _
& "IIF(物理 Is Null,'物理',Null) As 物理,IIF(化学 Is Null,'化学',Null) As 化学,IIF(生物 Is Null,'生物',Null) As 生物"
IIF1 = "IIF(组合='物化生',物理 Is Null Or 化学 Is Null Or 生物 Is Null,IIF(组合='物化地',地理 Is Null Or 物理 Is Null Or 化学 Is Null," _
& "IIF(组合='政史地',政治 Is Null Or 历史 Is Null Or 地理 Is Null,政治 Is Null Or 历史 Is Null Or 生物 Is Null))))"
IIF2 = "IIF(组合='物化生',物理&' '&化学&' '&生物,IIF(组合='物化地',地理&' '&物理&' '&化学," _
& "IIF(组合='政史地',政治&' '&历史&' '&地理,政治&' '&历史&' '&生物)))"
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
StrSQL = "Select 班级,考号,姓名," & S & ",组合 From [Sheet1$A:M] Where 语文 Is Null Or 数学 Is Null Or 英语 Is Null Or(" & IIF1
StrSQL = "Select 班级,考号,姓名,语文&' '&数学&' '&英语&' '&" & IIF2 & " From (" & StrSQL & ") "
Arr = Cn.Execute(StrSQL).GetRows
For i = 0 To UBound(Arr, 2)
Arr(3, i) = Replace(Application.Trim(Arr(3, i)), " ", ",")
Next i
Range("O17").Resize(i, 4) = Application.Transpose(Arr)
End Sub |
|