StealthRT StealthRT - 1 year ago 92 Question Excel move to next row

Hey all I am looking to see how to go about moving 1 row over where I am currently in my spreadsheet.

I have tried:

Dim xlsApp As Excel.Application
Dim xlsWB As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim xlsCell As Excel.Range

xlsCell = xlsSheet.Range("A1", "A100")

For Each oRowRange As Excel.Range In xlsCell.Rows
For Each oCellRange As Excel.Range In oRowRange.Columns

If colorRGB = "252, 213, 180" Then
oCellRange.Offset(0, 1).Select()
End If

In the example above, it keeps putting the same text:



When it really should be:



So any help would be great!

Answer Source

I think your issue is that you use the same line twice Debug.WriteLine(oCellRange.Text). After the first one, the oCellRange isn't changed. You're using .Select, kind of. You do .Select, but then never use Selection...this is a good thing. However, just tweak that second line and remove the .Select line:

     Debug.WriteLine(oCellRange.Offset(0, 1).Text)

Edit: Alternatively, you could replace the .Select line with Set oCellRange = oCellRange.Offset(0,1) and leave that third line as is. However, I don't suggest this and would personally keep the .Offset() method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download