Name Sheet with Input Box and text

R

ra

Hello,

I am trying to build a macro to add code to the front of the current
sheet name through an input box.

eg. enter F01 into box and all sheets change to F01_sheet1, F01_sheet2
etc.

I can get my code to rename based on input but how do I combine this
to existing sheet name?

Sub Namesheets()
'
Dim Dept_Code As String
Dept_Code = InputBox("Enter Dept Code (e.g. F01)")
'
Sheets("Weekly Sales Input Template").Select
Sheets("Weekly Sales Input Template").Name = Dept_Code

End Sub

Any help would be great
 
P

paul.robinson

Hi
Is this what you want?

Sheets("Weekly Sales Input Template").Name = Dept_Code & "_" &
Sheets("Weekly Sales Input Template").Name

If you need this in a loop for all sheets do

for each wks in Activeworkbook.Worksheets
wks.Name = Dept_Code & "_" & wks.name
next wks

regards
Paul
 
R

ra

Hi
Is this what you want?

Sheets("Weekly Sales Input Template").Name = Dept_Code & "_" &
Sheets("Weekly Sales Input Template").Name

If you need this in a loop for all sheets do

for each wks in Activeworkbook.Worksheets
    wks.Name = Dept_Code & "_" & wks.name
next wks

regards
Paul









- Show quoted text -

Thanks Paul, that work perfectly.
I have been trying something similar but kept getting an error
"Expected end of statment"... thanks again for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top