Using the result of an input box

  • Thread starter Thread starter sus1e
  • Start date Start date
S

sus1e

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
 
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
 
Wonderful, Thanks.

I was half way there and knew that as soon as someone with brains came along
it would be sorted for me.

Thanks again!
 

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

Back
Top