Home > Mobile >  How to get all values of first row of excel - vba
How to get all values of first row of excel - vba

Time:12-23

I want to get all values (not empty) of first row of excel .

oBook.Sheets("Sheet1").Rows(1).End(xlDown).column

but I think this is wrong. I want to loop it and show value inside a MsgBox.

CodePudding user response:

Loop Through the Cells of the Header Row

Dim ws As Worksheet: Set ws = oBook.Sheets("Sheet1")

Dim hrg As Range
Set hrg = ws.Range("A1", ws.Cells(1, ws.Columns.Count).End(xlToLeft))

Dim hCell As Range

For Each hCell In hrg.Cells
    MsgBox hCell.Address(0, 0) & " = " & hCell.Value
Next hCell
  • Related