ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using the result of an input box (https://www.excelbanter.com/excel-programming/405902-using-result-input-box.html)

sus1e

Using the result of an input box
 
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

[email protected]

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



sus1e

Using the result of an input box
 
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!

" wrote:

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





All times are GMT +1. The time now is 01:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com