Search code examples
vbaloopscell

Get the the column value of a selected cell through .address vba


I need to find a cell based on its value. Then I need to extract the value of a column from a selected cell and use it in my loop to iterate through. When I try to use .address it gives me an error

 Set selectedCell = Worksheets("Sheet1").Rows(3).Find("Start", LookIn:=xlValues)
 selectedCell.select
 Selection.Address

 While Not IsEmpty(Cells(3, EXTRACTED COLUMN VALUE HERE))

 

Solution

  • The selectedCell knows its column - no need to select it. Like this:

    Set selectedCell = Worksheets("Sheet1").Rows(3).Find("Start", LookIn:=xlValues)
    
    While Not IsEmpty(Cells(3, selectedCell.Column))