求教:下面标红色的代码怎么能写得简化一点
Sub 资产负债()
Dim cnADO, rsADO As Object
Dim strPath, strTable, strSQL As String
Set cnADO = CreateObject("ADODB.Connection")
strPath = "F:\报表类工作\张文超报表\合并报表\22.9月合并报表\2209合并3家(报集团).xlsx"
'建立连接
cnADO.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 8.0;hdr=no;imex=1';data source=" & strPath
'2022-9-30数据,如果行次有变化要改相应的ARR的数字
arr = Array(6, 3, 8, 4, 9, 5, 10, 6, 13, 9, 14, 10, 24, 18, 26, 20, 27, 21, 28, 22, 29, 25, 34, 28, 36, 31)
For i = LBound(arr) To UBound(arr) Step 2
strTable = "[报集团3家资产负债$C" & arr(i) & ":C" & arr(i) & "]"
strSQL = "select * from " & strTable
Cells(arr(i + 1), "D").CopyFromRecordset cnADO.Execute(strSQL)
Next i
arr = Array(6, 38, 8, 39, 9, 40, 10, 41, 11, 42, 12, 45, 15, 49, 32, 62, 39, 63, 41, 66, 42, 67)
For i = LBound(arr) To UBound(arr) Step 2
strTable = "[报集团3家资产负债$G" & arr(i) & ":G" & arr(i) & "]"
strSQL = "select * from " & strTable
Cells(arr(i + 1), "D").CopyFromRecordset cnADO.Execute(strSQL)
Next i
cnADO.Close
Set cnADO = Nothing
End Sub
|