Macro to loop through multiple rows of cell references

paul_sykes00

Board Regular
Joined
May 7, 2012
Messages
53
Hi there,

I have a excel sheet1 in which various cells reference cellvalues from the first row of cells on sheet2. (eg. Cell B15 on sheet1 mighthave the formula =sheet2!A1)

I am trying to create a macro that will run my existingmacro (lets call it macroX) then change the references in sheet1 to the secondrow of cells on sheet2 and repeat through all rows of cells until no more datais included on the row in sheet2.

Hope that makes sense. Thanks in advance for your help

 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Welcome to the Forum!

I'd do it like this:

Sheet1!B15: =INDEX(Sheet2!A:A,No)
where No is a range name, which you can set manually to 1 or 2 or 3 ....

Code:
Sub MyLoop()

    Dim i As Long
    
    Application.ScreenUpdating = False
    
    For i = 1 To Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
        Range("No").Value = i
        Call MacroX
    Next i
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Thanks for your response Stephen. Marco just seems to stop wen it gets to Range("No").Value = i

Any idea what I am doing wrong?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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