Check if cellvalue is equal to any tab/worksheet name in Workbook

Golaidron

Board Regular
Joined
Jan 23, 2013
Messages
83
Office Version
  1. 365
Platform
  1. Windows
Hi Guru's and Master's in Excel and VBA

In my workbook I created new tabs in based on the cell value in D3 and a macro attached to a command button.

The question is:

1. Is it possible to get Excel with vba or formula to check if the value D3.value is equal to any of my existing tabs? (Hope to avoid duplicates of tab names when i add the next one.)
2. If the value in D3 corresponds with any of my existin tabs, can i get a warning? Messagebox or D3's backgroundcolor turns Red?
3. If I change the value again in D3, can I get Excel to check name vs tabs again?

Hope to hear from you soon

Best regards

Golaidron
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Maybe you can adapt this code:
VBA Code:
Sub test()
    If Evaluate("isref('" & Range("D3") & "'!A1)") Then
        MsgBox ("Sheet exists.")
    Else
        MsgBox ("Sheet does not exist.")
    End If
End Sub
 
Upvote 0
Hi mumps.
That macro work great without any changes, thanks alot.

If I like this macro to run automatic when i change the value in D3, is that possible?

Best regards

Golaidron.
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Change the value in D3 and press the RETURN key.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Address(0, 0) <> "D3" Then Exit Sub
    If Evaluate("isref('" & Target & "'!A1)") Then
        MsgBox ("Sheet exists.")
    Else
        MsgBox ("Sheet does not exist.")
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,411
Messages
6,119,356
Members
448,888
Latest member
Arle8907

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