VBA Insert Formula based on Worksheet Name

daveasu

Board Regular
Joined
Jan 4, 2012
Messages
53
I have a workbook with multiple worksheets. I need VBA to insert formulas based on the worksheet name.

For example: a formula that will reference a value on another sheet in the workbook.

The sheet names are assigned dynamically with a 6-digit account numbers added to the existing sheet names earlier in the macro.

I tried using Application.Caller, but received an error message.


Code:
If Wkb.Sheets(Sheets.Count).Name Like "*Supplies" ThenRange("G45").Value = "=SUM(G9:H43)"
ElseIf Sheets(Sheets.Count).Name Like "*Travel" Then
Range("B7:B14").Columns.AutoFit
' Range("B15").Value = "='" & Application.Caller.Worksheet.Name & "'!H37"
End If


 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I am not really clear on what you are trying to achieve, the way I read this....

If the last sheet in the workbook has "supplies" in the Sheets Name then you want to sum a range an put it in the ActiveSheet Range G45

Otherwise if the last sheet in the workbooks name end with "travel" then you want to make Range B15 of the ActiveSheet equal H37 from some other sheet?

What is this other sheet? How is it being determined or identified?
 
Upvote 0

Forum statistics

Threads
1,221,441
Messages
6,159,904
Members
451,601
Latest member
terrynelson55

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