Loop Macro

paul_sykes00

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

I have the below macro. I am trying to get it to loop. Where each time the R[-1] part increases by 1 and keeps repeating until it finds an empty cell

Sub Test
Sheets("Sheet1").Select
Range("C3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=Sheet2!R[-1]C[-2]"
Range("C4").Select

Call MACROX
End Sub

Hope that makes sense. Thanks in advance
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
This work?

Code:
Sub Test()
Dim Aloop As Integer
Dim LastRowNo As Long
Dim RowInc As Integer


Sheets("Sheet1").Select
LastRowNo = Sheets("Sheet1").Range("C65536").End(xlUp).Row
RowInc = -1


For Aloop = 3 To LastRowNo
    Range("C" & Aloop).Select
    If Trim(Range("C" & Aloop).Value) = "" Then Exit For
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=Sheet2!R[" & RowInc & "]C[-2]"
    RowInc= RowInc-1
Next Aloop
Call MACROX
End Sub
 
Last edited:
Upvote 0
Thanks for your response

Sorry. I should have probably been clearer.

1st Loop
Take the value from cell A2 sheet 2, paste it into cell C3 sheet 3, then run the macro

2nd Loop
Take the value from cell A3 sheet 2, paste it into cell C3 sheet 3, then run the macro

3rd Loop
Take the value from cell A4 sheet 2, paste it into cell C3 sheet 3, then run the macro

and so on until value taken from sheet 2 is blank
 
Upvote 0
Maybe
Code:
Sub Test
dim i as long
    for i = 2 to sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
    sheets("Sheet3").cells(3,3).value2 = sheets("Sheet2").cells(i,1).value2
    Call MACROX
    next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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