Using the result of an input box
Sub GetandUseInput()
Dim myInput as String 'declare variable
myInput = InputBox("Input your week number", "InputBox Title")
If myInput = "" then 'Cancel was clicked
Exit Sub
Else
ActiveSheet.Name = "Week" & myInput
'some other stuff using myInput
End if
End Sub
This sub first declares a string variable called myInput. Inputboxes
take strings (text) as input. The value of myInput is then equal to
the value in the InputBox.
The active worksheet is then given the name "Week" & myInput. The "&"
operand is used to connect strings, so if 3 was entered in the
inputbox you would see the Activesheet being renamed as "Week3".
You can also use
Application.InputBox
This gives you a slightly different kind of inputbox which allows you
to specify the type of the input and you will also need
Dim myInput as Variant
the input can now be a number or string or.. See the Help.
regrads
Paul
On Feb 11, 12:42*pm, sus1e wrote:
Hi,
I am trying to get my brain around how to take the information from an input
box and use that data to rename the excel sheet.
For example, I want to prompt for a week number and then rename the sheet to
be that week number.
I then want to use the Week number for other things.
I am still fairly new to excel programming and just can't figure it out at
the moment. Any help would be great.
Thanks
|