VBA input box help

Leyton

New Member
Joined
May 26, 2011
Messages
13
Hi,

Pretty sure this should be an easy one! I'm just starting out so need a little bit of a push in the right direction.

I want a bit of code that allows the user to enter in a value, then i want to use this value to name the newly created tab ( i already have this bit of code), i will also need to add some words after the value the user enters,

so for example if the user enters ONE in the input box, then i need the newly created tab to be called ONE PROMO,

i will probably need a warning on the amount of characters the user enters so it doesnt cause an error when naming the tab?

Any suggestions will be greatly appreciated!

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Example:

Code:
Sub Test()
    Dim Answer As Variant
    Answer = InputBox("Enter sheet name")
    If Len(Answer) > 0 Then
        Worksheets.Add.Name = Answer & " PROMO"
    End If
End Sub
 
Upvote 0
Hi Andrew,

Thanks for the reply, I'm trying to add your code into what i have existing but it is coming up with an error saying - Run time error 424, Object required, do you have any suggestions? I have copied in below what i have done -

Sub NewPromo()
'
' NewPromo Macro
' Adds in new tabs to create a new promo
'
'
Application.ScreenUpdating = False
Dim Answer As Variant
Answer = InputBox("Title of New Promotion", "New Tab Name")
Sheets(Array("Promo", "P&L")).Select
Sheets(Array("Promo", "P&L")).Copy Before:=Sheets(4)
If Len(Answer) > 0 Then
Sheets("Promo (2)").Select
Add.Name = Answer & " PROMO"
Sheets("P&L (2)").Select
Add.Name = Answer & " PROMO"
End If
 
Upvote 0
Sorry, just added in Worksheets. in front of the add name and its working however now its just creating the new tabs called what i want but no data and the data is going on the old tabs called Promo (2) & P&L (2)
 
Upvote 0
The same answer as the user gave in the input box, so if they enetered ONE in the input box we would have 2 tabs called ONE Promo and ONE P&L
 
Upvote 0
I think you just have to rename the copied sheets.
If so, try the below code.

Code:
Sub NewPromo()
'
' NewPromo Macro
' Adds in new tabs to create a new promo
'
'
Application.ScreenUpdating = False
Dim Answer As Variant
Answer = InputBox("Title of New Promotion", "New Tab Name")

Sheets(Array("Promo", "P&L")).Select
Sheets(Array("Promo", "P&L")).Copy Before:=Sheets(4)

If Len(Answer) > 0 Then
    Sheets("Promo (2)").Name = Answer & " PROMO"
    Sheets("P&L (2)").Name = Answer & " P&L"
End If

End Sub
 
Upvote 0
Try:

Code:
Sub NewPromo()
'
' NewPromo Macro
' Adds in new tabs to create a new promo
'
'
    Application.ScreenUpdating = False
    Dim Answer As Variant
    Answer = InputBox("Title of New Promotion", "New Tab Name")
    If Len(Answer) > 0 Then
        Sheets("Promo").Copy Before:=Sheets(4)
        ActiveSheet.Name = Answer & " PROMO"
        Sheets("P&L").Copy Before:=Sheets(5)
        ActiveSheet.Name = Answer & " P&L"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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