|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
vba:
Sub Macro1()
Dim cnn As Object, sql$, lr&, i%
lr = Sheets("Sheet1").[a1].CurrentRegion.Rows.Count
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=excel 8.0;Data Source=" & ThisWorkbook.FullName
For i = 1 To 26 Step 2
If sql <> "" Then sql = sql & " union all "
sql = sql & "select * from [Sheet1$" & Cells(1, i).Resize(lr, 2).Address(0, 0) & "]"
Next
' sql进一步处理
[a1].CurrentRegion.Offset(1, 0).ClearContents
[a2].CopyFromRecordset cnn.Execute(sql)
cnn.Close
Set cnn = Nothing
End Sub |
|