Need help with numbers in VBA

Rockhopper3

Board Regular
Joined
Apr 11, 2006
Messages
131
I have a formula that adds 1 to a numbe. This number then replaces another number in the worksheet name. When VBA adds the numbers, it takes away the zero in front of it. Does anyone know how to solve this so the sheet name will display as Jan.-07, etc?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

try


format(no,"00")

where no is your number.


Tony
 

Rockhopper3

Board Regular
Joined
Apr 11, 2006
Messages
131
Number is typed in by user in userform.
The following code is then used.

Code:
Dim yr As String
Dim yr1 As String
yr = TextBox1.Value + 1
yr1 = TextBox1.Value - 1

Thoughts?
 

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

The result of a textbox is text. You have to convert the text to a number before you can perform maths.

yr = val(textbox1.value) + 1
yr1 = val(textbox1.value) - 1

Once you have a numeric response, you can use the format function to make sure of the output structure.


Tony
 

Watch MrExcel Video

Forum statistics

Threads
1,133,459
Messages
5,658,893
Members
418,475
Latest member
ExcelBeginner233

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
Top