Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50090

Leading zero required in this textbox for numbers 1 - 9. Why?

$
0
0
The following code works as desired except it requires a leading zero for numbers 1 – 9
The problem without leading zero is it doesn’t add 1 to the numbers 10 plus as it does when a leading zero 01 - 09
Why does it happen?
Can anyone provide a better solution than my initial default value zero (0) in the textbox (which then needs to be left in the textbox).
Code:

Private Sub CommandButton1_Click()
    Application.Calculation = xlCalculationManual
   
'  Transfer the create a gap number to test indicators
    Range("J68") = TextBox1.Text
   
'  Select the start of range requiring possible alteration.
    Range("E69").Select
   
'  Add 1 to each if greater than the textbox entry.
    Do While ActiveCell.Value <> Empty
        If ActiveCell.Value > TextBox1.Text Then
            ActiveCell.Value = ActiveCell.Value + 1
            Else
        End If
    ActiveCell.Offset(1, 0).Select
    Loop
       
               
    Application.Calculation = xlCalculationAutomatic



End Sub

Sample worksheet of relevant portion attached
Attached Files

Viewing all articles
Browse latest Browse all 50090

Trending Articles