VB大虾们有空吗?我要给EXCEL第8列中找有相同的单元格,但是不出结果,麻烦您了.

来源:百度知道 编辑:UC知道 时间:2024/05/30 19:28:25
Private Sub Command4_Click()
Dim app As Object
Dim bpp As Object
Dim cpp As Object

Set app = CreateObject("excel.application")
app.Visible = True

Set bpp = app.Workbooks.Open("J:\h\f.xls")
Set cpp = bpp.worksheets(1)
cpp.Activate

Dim i, j As Integer
i = 6
For i = 6 To 115
j = i + 1
While (j <= 115)
If app.cells(i, 8) = app.clls(j, 8) Then Text1.Text = app.cells(i, 8)
j = j + 1
Wend

Next i
End Sub

暂时发现三个问题:
1、app是VB的保留字,是VB的应用程序对象(比如app.path就是程序本身所在路径),所以不能作为变量名的;
2、If app.cells(i, 8) = app.clls(j, 8) 中的clls应该是cells,不知道是不是你的笔误。
3、If app.cells(i, 8) = app.clls(j, 8) Then Text1.Text = app.cells(i, 8) 中的app都应该是cpp才对吧?