0

I'm writing code in VBA, and I'm trying to accomplish the following :

  • Select a range from a sheet
  • Loop through that range's rows
  • Compare the 3 cell value in the row to a value
  • Do stuff....

I searched through the Internet, but didn't find a way to access that 3rd cell...

Thanks in advance !

Some code for you nerds :

For Each ProdRow In DayProd.Rows
  saisi = False
  Do While ((Not IsEmpty(Selection.Value)) And (Not saisi))
    If (Selection.Value = ProdRow(*Select that 3rd cell*).Value) Then
        ....                  
    End If
  Loop
Next
Rdster
  • 1,846
  • 1
  • 16
  • 30
Hamza
  • 15
  • 1
  • 5
  • 1
    You would benefit greatly from reading this: [How to avoid using Select in Excel VBA macros](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros). You are also looking for the [Range.Offset](https://msdn.microsoft.com/en-us/library/office/ff840060.aspx) property. Hard to give more tips without more information. – tigeravatar May 16 '17 at 14:33
  • `If Selection.Value = ProdRow.Offset(0, 3).Cells(1, 1).Value Then` – omegastripes May 16 '17 at 14:35
  • I'm not using Select, I'm seeking just the way to refer to a cell : each row containes three cells (That is 3 columns), how to get that done ? – Hamza May 16 '17 at 15:06

1 Answers1

2

You could use the Offset function like @ omegasripes mentioned

Or the Cells function:

Cells(ProdRow.Row, ProdRow.Column+3)

Or if you want the third column ("C") of that row just:

Cells(ProdRow.Row, 3)
Holger
  • 320
  • 1
  • 10
  • The ProdRow adress is $C$4:$E$4, isn't there a way to refer to those cells Inside the row range ? – Hamza May 16 '17 at 15:12
  • 1
    yes, if this is your address, then you could refer to the third column like this: `ProdRow.Columns(3).Value` – Holger May 16 '17 at 15:16