What is the fastest way to go back through an Excel Range object?

I am using VBA in Excel VBE, but C # or vb is fine. The concept must be consistent with all languages.

+5
source share
2 answers

Not sure what you mean. Do you want to go from bottom to top, not 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
+3
source

, : () . .NET, (, , , ), .

VBA - :

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
+1

All Articles