excel vba : selected cells loop

后端 未结 2 1536
北海茫月
北海茫月 2020-12-30 07:01

Would like to iterate each row in a selection in excel VBA.

I have:

Dim rng As Range
Dim s As String
Set rng = Application.Selection
Debug.Print \"c          


        
2条回答
  •  礼貌的吻别
    2020-12-30 07:41

    A general solution to looping through a range of cells in Excel:

    Sub LoopSelection()
    
        Dim cel As Range
        Dim selectedRange As Range
    
        Set selectedRange = Application.Selection
    
        For Each cel In selectedRange.Cells
            Debug.Print cel.Address, cel.Value
        Next cel
    
    End Sub
    

    Iterates from top-left most cell, across then down.

提交回复
热议问题