excel vba bug排除

Sub 寻找编号和价格()

    Dim loo As Range
    Dim bh As String
    bh = [b7].Value
    Dim yy As Range
    Dim bhl As Range
    Set bhl = Range("b:b")
    Dim fist As String
    
    Set loo = Range("b7")
    
    
    Do
    
    If Len(loo) > 0 And loo.Value <> 0 Then
    Set yy = bhl.Find(what:=loo.Value, lookat:=xlWhole)
    
    fist = yy.Address
    
    
   
    
    Do
    
     If yy.Address <> loo.Address Then
   
        If yy.Offset(0, 4).Value = loo.Offset(0, 4).Value Then
           
        loo.Offset(0, 3).Value = yy.Offset(0, 3).Value + loo.Offset(0, 3).Value
           loo.Offset(0, 5).Value = yy.Offset(0, 5).Value + loo.Offset(0, 5).Value
            loo.Interior.ColorIndex = 9
            yy.Interior.ColorIndex = 6
          yy.Value = 0
           yy.Offset(0, 3).Value = 0
          yy.Offset(0, 5).Value = 0
            
            
            
            
        End If
       
    End If
      Set yy = bhl.FindNext(yy)
    Loop While yy.Address <> fist
    
   
    
    End If
    
    Set loo = loo.Offset(1, 0)
 Loop While loo.Address <> Cells(Range("b:b").Rows.Count, 2).End(xlUp).Address

End Sub


一共犯了无数个错误,
解决了几个问题
   1\单元格为空的情况  len(cell)>0
   2\findnext()函数,不能找到自己,不能默认第一个是自己.这个代码还有优化的可能...不能从第一个开始,自己

你可能感兴趣的:(code)