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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,525
Members
448,969
Latest member
mirek8991

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