zopey 发表于 2018-8-6 14:15
For i = 3 To Range("A65536").End(xlUp).Row
For Arr_CateNumI = 0 To Arr_CateNumS
If Cells(i, 2).Val ...
用你的方法的确就好了!!非常感谢!!!我下面的代码,是插入数据到数据库,和上面的是一起的,不知道为什么执行到for s =i那一句后,就直接跳到对话框那里去了,并没有执行insert语句,能帮我看一看吗T T
- For S = i To Range("A65536").End(xlUp).Row
- For l = 1 To Range("IV1").End(xlToLeft).Column
- If IsNull(Cells(S, l)) = True Then
- Cells(S, l) = Null
- End If
- Next l
- Sql = "insert into list values('" & Cells(S, 2) & "','" & Cells(S, 3) _
- & "','" & Cells(S, 4) & "','" & Cells(S, 5) & "','" & Cells(S, 6) & "'," & Cells(S, 7) & "," & Cells(S, 8) & ",'" & Cells(S, 9) & "','" & Cells(S, 10) & "'," & Cells(S, 11) & "," & Cells(S, 12) & ",'" & Cells(S, 13) & "', '" & Cells(S, 14) & "', '" & Cells(S, 15) & "','" & Cells(S, 16) & "'," & Cells(S, 17) & ",'" & Cells(S, 18) & "'," & Cells(S, 19) & "," & Cells(S, 20) & "," & Cells(S, 21) & "," & Cells(S, 22) & "," & Cells(S, 23) & ",'" & Cells(S, 24) & "','" & Cells(S, 25) & "','" & Cells(S, 26) _
- & "','" & Cells(S, 27) & "','" & Cells(S, 28) & "','" & Cells(S, 29) & "','" & Cells(S, 30) & "'," & Cells(S, 31) & "," & Cells(S, 32) & "," & Cells(S, 33) & "," & Cells(S, 34) & "," & Cells(S, 35) & "," & Cells(S, 36) & "," & Cells(S, 37) & "," & Cells(S, 38) & "," & Cells(S, 39) & "," & Cells(S, 40) & "," & Cells(S, 41) & "," & Cells(S, 42) & "," & Cells(S, 43) & "," & Cells(S, 44) _
- & "," & Cells(S, 45) & "," & Cells(S, 46) & "," & Cells(S, 47) & ",'" & Cells(S, 48) & "','" & Cells(S, 49) & "')"
- cnn.Execute Sql
- Next S
- MsgBox "数据添加成功!", vbExclamation
- Dim xRs As New ADODB.Recordset
- Sql = " Select * from list"
- xRs.Open Sql, cnn, 1, 3
- Sheet2.Range(Sheet2.Range("A3"), Sheet2.Range("A2").End(xlDown)).EntireRow.Clear
- Sheet2.Range("A3").CopyFromRecordset xRs
- xRs.Close
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |