Iterating through populated rows

前端 未结 3 1172
北恋
北恋 2020-11-27 14:09

So I am trying to iterate through a worksheet in an Excel spreadsheet using VBA. I want to iterate through each row, and then through each column, and despite googling, I ca

3条回答
  •  悲哀的现实
    2020-11-27 14:38

    It looks like you just hard-coded the row and column; otherwise, a couple of small tweaks, and I think you're there:

    Dim sh As Worksheet
    Dim rw As Range
    Dim RowCount As Integer
    
    RowCount = 0
    
    Set sh = ActiveSheet
    For Each rw In sh.Rows
    
      If sh.Cells(rw.Row, 1).Value = "" Then
        Exit For
      End If
    
      RowCount = RowCount + 1
    
    Next rw
    
    MsgBox (RowCount)
    

提交回复
热议问题