How to avoid using select in VBA for variable cell ranges?

前端 未结 4 704
有刺的猬
有刺的猬 2021-01-27 05:59

I have heard of the dislike for using .select in VBA for excel macros, but I am wondering how my particular goal can be achieved without its use? For example, say there is a cel

4条回答
  •  借酒劲吻你
    2021-01-27 06:42

    Here are two iterate rows to based on the ActiveCell.

    Sub Examples()
    
        Dim Target As Range
        Dim x As Long
    
        Set Target = ActiveCell
    
        Do Until Target.Value = "Commodity"
            Set Target = Target.Offset(0, 1)
        Loop
    
        Do Until ActiveCell.Offset(x, 1).Value = ""
            x = x + 1
        Loop
    
    End Sub
    

提交回复
热议问题