Private Sub CommandButton2_Click()
Dim str As String
Dim b, d0, d1 As Range
Dim s, t, s1, t1, h1, h0 As Long
Dim v, tnt As Long
Dim i, j, k, l, m, n As Integer
Dim wr As RangeIf TextBox6.Text = "" Then
MsgBox "请输入需要查找的物料型号!"Else
word1 = "物料代码"
Set d0 = xls3.Range("a2:t65536").Find(word1, lookat:=xlWhole)       ‘表xls3为已经打开的表,作为全局变量存在
If Not d0 Is Nothing Then
h0 = d0.Column
MM = ChgNumToABC(h0)
End Ifword2 = "MANUFACTURE P/N"
Set d1 = xls3.Range("a2:t65536").Find(word2, lookat:=xlWhole)
If Not d1 Is Nothing Then
h1 = d1.Column
h2 = d1.Row
End Ifstr = TextBox6.TextSet b = xls3.Range(Cells(2, h1), Cells(65536, h1)).Find(str, lookat:=xlPart)’这句话这样写可以嘛,始终报错,因为列为变量,需要制定区域范围
  If Not b Is Nothing Then
    v = b.Row
    s = xls3.Cells(v, h1).Value
    t = xls3.Cells(v, h0).Value
    ListBox1.AddItem (t)
    ListBox2.AddItem (s)
    
Do
     
     Set b = xls3.Range(Cells(2, h1), Cells(65536, h1)).FindNext(b) ‘ 同样报错
     tnt = b.Row
     s1 = xls3.Cells(tnt, h1).Value
     t1 = xls3.Cells(tnt, h0).Value
     ListBox1.AddItem (t1)
     ListBox2.AddItem (s1)
Loop Until b Is Nothing Or b.Row = vi = 0
Do While i < ListBox1.ListCount - 1
   j = i + 1
   Do While j <= ListBox1.ListCount - 1
      If ListBox1.List(i) = ListBox1.List(j) Then
         ListBox1.RemoveItem j
      Else
      j = j + 1
      End If
   Loop
   i = i + 1
Loop
k = 0
Do While k < ListBox2.ListCount - 1
   l = k + 1
   Do While l <= ListBox2.ListCount - 1
      If ListBox2.List(k) = ListBox2.List(l) Then
         ListBox2.RemoveItem l
      Else
      l = l + 1
      End If
   Loop
   k = k + 1
LoopEnd If
MsgBox "ok!"
End IfEnd Sub