Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using macro to add new sheets and change file name 1

Status
Not open for further replies.

farnye

Civil/Environmental
May 22, 2003
14
0
0
US
Im trying to see if the following problem is even do-able.

When doing traffic forecasting, i need to add/copy 2 new sheets in excel each time an additional intersection is started. By using the macro recorder, i have been successful in doing the following;

-copying from 2 previous sheets to make the new sheets.
-rename the new sheets to a generic name
-change the formulas in the new sheet 2 to ref back to new sheet 1 using the new generic name.

My question is can i add an extra step while the macro is running, so an input box can pop up, allwoing me to manual input what i want the sheets to be named(and also apply that name to the formula changes)??

currently i have to wait till it is done running and then change the sheet names and formluas by hand to the correct names i want, making the macro seem worthless.
 
Replies continue below

Recommended for you

Try this - need to adapt obviously for your file naming protocol!

Sub Macro1()

Message = "Enter new sheet name"
Title = "Input"
Myvalue = InputBox(Message, Title, "")

Sheets("Sheet2").Copy After:=Sheets("Sheet2")
Sheets("Sheet1").Copy After:=Sheets("Sheet2")

Sheets("Sheet1 (2)").Name = Myvalue + "_A"
Sheets("Sheet2 (2)").Name = Myvalue + "_B"

Sheets(Myvalue + "_B").Select
Cells.Replace What:="Sheet1", Replacement:=Myvalue + "_A", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False

End Sub

 
I ran the script and it would only copy the sheets and then stop.

However, if i break it into two different macros, i can get the copying and the renaming to each work seperatly.
 
I got it to work now!

It was something that was wrong with the workbook i was using.

Thanks for your help!
 
Status
Not open for further replies.
Back
Top