Using macro to reference previous sheet in formula

mickygoalie

New Member
Joined
Nov 23, 2010
Messages
18
Hi
I don't know about writting Macros, but I have recorded the following one.

Sub Change()
'
' Change Macro
'
'
ActiveCell.FormulaR1C1 = "=April!RC"
Range("B5").Select
Selection.AutoFill Destination:=Range("B5:B22"), Type:=xlFillDefault
Range("B5:B22").Select
Selection.Copy
Range("F5").Select
ActiveSheet.Paste
Range("J5").Select
ActiveSheet.Paste
Range("N5").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=18
Range("B29").Select
ActiveSheet.Paste
Range("J29").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=21
Application.CutCopyMode = False
End Sub


However rather than using the line below which looks at the sheet named April, I would like it to look at the sheet to the left of the active sheet.

ActiveCell.FormulaR1C1 = "=April!RC"

I'm sure this is really easy, but I just don't know anything yet.

Can anyone recommend a good beginners guide to help me learn about VBA?

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Code:
prevname=Sheets(ActiveSheet.Index - 1).name
ActiveCell.FormulaR1C1 = "=" & prevname & "!RC"
 
Last edited:
Upvote 0
Code:
prevname=Sheets(ActiveSheet.Index - 1).name
ActiveCell.FormulaR1C1 = "=" & prevname & "!RC"

Years later this is still relevant! However, patel45, I am using just your coding (as opposed to the full coding from the original post), and am having a slight issue. The coding seems to have an problem with dashes. I am putting together a workbook with 1 sheet for each week in the year so the date format "1-3" is essential in labeling each sheet. If you wouldn't mind, could you modify the code to both deal with dashes better and, perhaps, iterate through all 52 sheets before stopping? I'd greatly appreciate it.

JV
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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