我正在通過VBA將ms訪問的數據填充到excel。我的數據庫包含許多組詳細信息,我想在羣體時間分隔組成員,問題是每個組的末尾我想在Excel表格中插入2行我使用下面提到的代碼,但是我不工作是否有可能?在excel中插入行
Dim varConnection
Dim varSQL
Dim cal, cal1, x
varConnection = "ODBC; DSN=MS Access Database;DBQ=table.accdb; Driver={Driver do Microsoft Access (*.accdb)}"
varSQL = "SELECT leftman.Productname,leftman.Description,leftman.SULM,leftman.MTR,leftman.meter1 FROM leftman INNER JOIN Product ON leftman.gid = Product.Productname ORDER BY Product.ID, leftman.ID"
With ActiveSheet.QueryTables.Add(Connection:=varConnection, Destination:=ActiveSheet.Range("B4"))
.CommandText = varSQL
.Name = "Query-39008"
.Refresh BackgroundQuery:=False
End With
x = Range("J5", Range("J5").End(xlDown)).Rows.Count
k1 = 5
k2 = 6
For i = 0 To x
s = k1 + i
s1 = k2 + i
If Range("J" & s & "").Value = Range("J" & s1 & "").Value Then
msgbox "same group"
Else
Range("J" & s & "").Select
ActiveCell.Offset(1).EntireRow.Insert
ActiveCell.Offset(1).EntireRow.Insert
k1 = 5 + 2
k2 = 6 + 2
End If
Next i
首先我找回GroupWise中的數據從訪問 X是我的行數 K1是小區1和K2是小區2我是小區1單元2通過循環比較,如果數據不是
比賽那麼它是使細胞後,我想插入2行