Define sheet names VBA

erlisocial

New Member
Joined
Feb 5, 2020
Messages
15
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi,

I have over 100 sheets with different names. (ABC, CDE, ENT etc). I have a VBA which requires the sheet selection many times throughout the code. I need to repeat the same code for the next sheet. Rather than me having to rename all the Sheets on my VBA code, is there a way were I can define that name and just change it once at the beginning of my statement and the Sheets to pick up that name and update my VBA code?

Many thanks in advance


VBA Code:
Sub Sheet1 ()


''
Sheets("ABC").Select
Sheets("ABC").Select
Sheets("ABC").Select
Sheets("ABC").Select

''
End Sub
 
How about an input box that changes the sheet name?


VBA Code:
Sub Test()
Dim ws As Worksheet
Set ws = InputBox("What Sheet to Name?")
'use ws to identify your sheet with your actions
'ie.  with ws
' Your code for the worksheet

End Sub
Thanks mate used Fluff's method but will keep your option as a backup. Cheers
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

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