For Each Cell search direction

bjorgen

New Member
Joined
Aug 23, 2011
Messages
33
I have a big table that I need to fill in values via vba.

Every row has a different formula assigned to it and I was wondering if i can force the VBA code to search down and then right instead of going right and then down.

Any help is appreciated here!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
For Each applied to a range goes across and down.

You could do do this:

Code:
    Dim myRange     As Range
    Dim rCol        As Range
    Dim cell        As Range
 
    Set myRange = Range("A1:C5")
 
    For Each rCol In myRange.Columns
        For Each cell In rCol.Cells
            ' do stuff
        Next cell
    Next rCol
 
Upvote 0
Instead of a For Each cell In someRange loop, use
Code:
For rowNum = 1 to n
    For ColNum = 1 to m
        With someRange.Cells(rowNum, colNum)
Actualy if each row has it's own formula

Code:
For rowNum = 1 to n
    someRange.Rows(i).FormulaR1C1 = myFormula(i)
Next rowNum
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,767
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top