VBA - How to refer to a different worksheet cell

ez08mba

Board Regular
Joined
Nov 1, 2011
Messages
225
Office Version
  1. 2016
Platform
  1. Windows
I'm having problems in editing my macro to refer to a different worksheet I referenced in while creating my macro. Below is my question with the code, which I thought I could paste in as an image and could not.

' QUESTION:
' "='Jan 16-Jan 22'!RC[-1]" -- This is the name of the sheet to the right of the sheet
' my macro creates and references. This sheet is the 6th sheet, and the sheet my macro
' creates will always be the 5th sheet.
' How do I change this code (i.e. "='Jan 16-Jan 22'!RC[-1]") to reference the 6th worksheet
' every time the 5th is created since the tab name of the 6th sheet will be different every time?

Range("C2").Select
ActiveCell.FormulaR1C1 = "='Jan 16-Jan 22'!RC[-1]"
Range("C3").Select
ActiveCell.FormulaR1C1 = "='Jan 16-Jan 22'!RC[-1]"
Range("C3").Select
Selection.AutoFill Destination:=Range("C3:C20"), Type:=xlFillDefault
Range("C3:C20").Select
Range("C5:C20").Select
Selection.NumberFormat = "General"
 
.Cells(3, .Columns.Count) 'references the last column on row 3 (IV in Excel 2003)

.End(xlToLeft).Column 'returns the number of the first column to the left that is not empty

If that's column 10 we need to deduct 2 (B3's column number) to get the offset of 8 in the formula.
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,223,713
Messages
6,174,043
Members
452,542
Latest member
Bricklin

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