UBound

A

Arturo

I’m looping through a bunch of columns.
I want to store the column indexes 1, 9, 18, 21 in a cell, whose named range
is Columns.
Not sure how to…

WORKING
rO = myRange.Rows.Count
coLArray = Array(1, 9, 18, 21)
For X_col = 0 To UBound(coLArray)

For Loop_rO = 4 To rO
Cells(Loop_rO, coLArray(X_col)).Select
Y_CellBase = ActiveCell.Value
Y_CellTest = Worksheets(2).Cells(Loop_rO, coLArray(X_col))
If Y_CellBase <> Y_CellTest Then
Worksheets(2).Cells(Loop_rO,
coLArray(X_col)).Interior.ColorIndex = 3
End If
Next Loop_rO

Next X_col


NOT WORKING
rO = myRange.Rows.Count
Columns2Check = Range("Columns")
coLArray = Array(Columns2Check)
For X_col = 0 To UBound(coLArray)

For Loop_rO = 4 To rO
Cells(Loop_rO, coLArray(X_col)).Select
Y_CellBase = ActiveCell.Value
Y_CellTest = Worksheets(2).Cells(Loop_rO, coLArray(X_col))
If Y_CellBase <> Y_CellTest Then
Worksheets(2).Cells(Loop_rO,
coLArray(X_col)).Interior.ColorIndex = 3
End If
Next Loop_rO

Next X_col


Appreciatively,
Arturo
 
T

Tom Ogilvy

also, if you use my approach, then your loop should be

For X_col = lbound(colArray) To UBound(coLArray)
 
A

Arturo

Not sure how to tweak the working example to accept the columns to loop
through from the same info in a cell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top