How to use Sheet name instead of Tab name?

Excelerate2

New Member
Joined
Mar 18, 2022
Messages
25
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
Hi folks! How do I replace the tab's name ('Electrical') with the actual Sheet name (Sheet 11)?
Whenever I try it doesn't work, here is the good working code below, just need to use the sheet name (Sheet11) instead of the tab name ('Electrical'):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target

If .Address(False, False) = "D107" Then
If IsEmpty(.Value) Then
Application.EnableEvents = False
.Formula = "=Electrical!I181"
Application.EnableEvents = True
End If
End If


All this does is simply inputs a cell reference from another tab in same workbook: 'Electrical' tab (cell I181) unless the target cell (D107) already has a value (is not blank).
And it should input it again if I clear (delete) the value in the target cell (D107).
Then I repeat this code for several more entries (below it) and then End Sub.
(All works perfectly above using the 'tab's name' but need to change it to 'Sheet name' in case user changes the tab name)

Any help would be great - Thanks much!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You have to use the tab name in a formula, but you can use the codename to get that:

Code:
.Formula = "='" & sheetcodename.name & "'!I181"

for example.
 
Upvote 0
Solution
You have to use the tab name in a formula, but you can use the codename to get that:

Code:
.Formula = "='" & sheetcodename.name & "'!I181"

for example.
Thanks, is there a better way to write this (instead of using .Formula)?
 
Upvote 0
You put it in place of your line that starts with .Formula. You will of course need to supply the correct code name for whichever sheet it is.
 
Upvote 0
Ok I see what you mean (replace the sheetcodename with the sheet name and add the .name after it),
Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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