Reference sheet name in code

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
365
Hi, the code below refers to sheet "quote", however I need it to reference the active sheet name because I sometimes change the name to something other than quote. Or it can reference the sheet name in cell C1. This cell has the following formula (=MID(CELL("filename",C1),FIND("]",CELL("filename",C1))+1,255) if it will have any bearing on this option. Thanks for the help.

VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)

    If IsEmpty(Sheets("QUOTE").Range("L9").Value) = False Then
    On Error Resume Next
    If Sh.Name = "TABLE PROD" Then
        MsgBox "NOTES:  " & Worksheets("quote").Range("L9")
    End If
    End If

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The simplest way would be to use the sheet codename. In the Project window of the editor you should see a list of sheets like
Sheet codenames.png

What is the name to the left of the Quote sheet?
 
Upvote 0
The name is Sheet14 (QUOTE).

What will happen if I duplicate the sheet and rename it? Will this solution carry over?
 
Upvote 0
No it wont, it will always look at sheet14. Is that what you want?
 
Upvote 0
As C1 just contains the name of that sheet, why not use Activesheet instead of the sheet name?
 
Upvote 0
Try
VBA Code:
If ActiveSheet.Range("L9").Value = "" Then
 
Upvote 0
Try
VBA Code:
If ActiveSheet.Range("L9").Value = "" Then

[/
[/QUOTE]

Try
VBA Code:
If ActiveSheet.Range("L9").Value = "" Then
I am realizing what I want to achieve is not possible as "table prod" needs to point to a certain named sheet. Once I move to sheet "table prod" then that becomes the active sheet. I would probably need a field in 'table prod" to refer to the sheet I want. Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

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