【发布时间】:2019-11-05 19:13:31
【问题描述】:
此代码用于查找第一个值,我需要它来捕获其中包含“120”的第一个单元格,这意味着 120、7120、31200 都包含重复项。另外,ID CODE 在 C 列,如何将 D 列的数据添加到列表框的第二列?
Dim AGCN As Long
Dim AGCL As String
Dim AGNN As Long
Dim AGNL As String
Dim i As Long
Dim rng As Range
Dim rownumber As Long
Dim AGC As Range
Dim AGN As Range
Dim firstaddress As Long
Dim nextaddress As Long
'Identify column letter
AGCN = Rows("1:1").Find(what:="ID CODE", lookat:=xlWhole).Column
AGCL = Split(Cells(1, AGCN).Address, "$")(1)
AGNN = Rows("1:1").Find(what:="NAME", lookat:=xlWhole).Column
AGNL = Split(Cells(1, AGNN).Address, "$")(1)
With Sheet1.Range(AGCL & ":" & AGCL)
Set c = .Find("*" & tbAC & "*", LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Value
Debug.Print firstaddress
With Me.ListBox2
.ColumnCount = 3
.ColumnWidths = "50;150;70"
.AddItem
.List(i, 0) = Str(firstaddress)
i = o + 1
End With ' code works up till this part
Do ' from here,
Set c = .FindNext(c)
If c Is Nothing Then
GoTo donefinding
ElseIf firstaddress <> c.Value Then
nextaddress = c.Value
Debug.Print nextaddress
With Me.ListBox2
.ColumnCount = 3
.ColumnWidths = "50;150;70"
.AddItem
.List(i, 0) = Str(nextaddress)
Debug.Print nextaddress
i = o + 1
End With
End If
Loop While c.Address <> firstaddress ' till here, it loops through all the other possible values but does not input onto listbox and it crashes my excel
End If
donefinding: Exit Sub
End With
目前没有错误信息,excel只是循环和崩溃。
【问题讨论】: