tags:

views:

331

answers:

2

The title pretty much says it all. I'm using VBA in the Excel VBE, but c# or vb are fine. The concept should hold true across the languages. Thanks.

+1  A: 

Not sure what you mean. You want to go through from the bottom to top, instead of top to bottom?

This should do:

Dim myrange As Range
Set myrange = Range("B3:E10")

Dim row As Integer, col As Integer
For row = myrange.Rows.Count To 1 Step -1
    For col = myrange.Columns.Count To 1 Step -1
        Debug.Print myrange(row, col).Value  
    Next col
Next row
BradC
Good solution BradC. +1
Jason Lepack
+1  A: 

If you're working with ranges of more than a few cells and don't need to modify the cells, always consider pulling the values into an array and working with that: the interaction between code and worksheet is relatively (very) expensive. If you're working from a .NET assembly, that goes double (maybe triple, maybe more) because there are several more steps involved in a round trip.

In VBA, something like this:

Dim vals As Variant
Dim row As Long, col As Long

vals = Range("A1:Z100") ' or whatever
For col = UBound(vals,2) To LBound(vals,2) Step -1
    For row = UBound(vals) To LBound(vals) Step -1
        DoSomethingInterestingWith vals(row, col)
    Next
Next
Mike Woodhouse