How to manipulate Spin Control?

DreyFox

Board Regular
Joined
Nov 25, 2020
Messages
61
Office Version
  1. 2016
Platform
  1. Windows
Hello, I have something I would like to do using spin control. So I'd like to have the spin control start counting at RH00000-00. Then when the hit the arrow key to the right, it becomes RH00001-00. Then when I hit it to the right again, it becomes RH00001-01. Is this doable with some VBA? Currently, I have the VBA code to do just basic RH0, RH1, etc. Any help would be greatly appreciated! Thank you!

VBA Code:
SpinButton1.SmallChange = 1
TextBox8.Text = "RH" & SpinButton1.Value
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
VBA Code:
SpinButton1.SmallChange = 1
TextBox8.Text = "RH" & Format(SpinButton1.Value, "00000-00")
 
Upvote 0
You can do something like this...
VBA Code:
Option Explicit

 Dim varString As String
 Dim varNClick, varNClick2
    
 Private Sub UserForm_Initialize()
 
    MsgBox ("RH00000-00")
    varNClick = 0
    varNClick2 = 0
    
End Sub

Private Sub SpinButton1_SpinUp()

    If varNClick = varNClick2 Then
        varNClick = varNClick + 1
    Else
        varNClick2 = varNClick2 + 1
    End If
EX:
    varString = "RH" & Format(varNClick, "00000") & "-" & _
                           Format(varNClick2, "00")
    MsgBox (varString)

End Sub
 
Upvote 0
You can do something like this...
VBA Code:
Option Explicit

Dim varString As String
Dim varNClick, varNClick2
   
Private Sub UserForm_Initialize()

    MsgBox ("RH00000-00")
    varNClick = 0
    varNClick2 = 0
   
End Sub

Private Sub SpinButton1_SpinUp()

    If varNClick = varNClick2 Then
        varNClick = varNClick + 1
    Else
        varNClick2 = varNClick2 + 1
    End If
EX:
    varString = "RH" & Format(varNClick, "00000") & "-" & _
                           Format(varNClick2, "00")
    MsgBox (varString)

End Sub
Is there a way to do this with ActiveX instead of UserForm?
 
Upvote 0
VBA Code:
SpinButton1.SmallChange = 1
TextBox8.Text = "RH" & Format(SpinButton1.Value, "00000-00")
This only increases the 2nd term 00 into the hundreds before I get 00001. I'd like to get 00000-> 00001 then 00 -> 01
 
Upvote 0
Yes, but take care where you will put initial values.
It may be event "Workbook_Open" or Worksheet_Activate instead UserForm_Initialize.
Example...
VBA Code:
Option Explicit

Dim varString As String
Dim varNClick, varNClick2
 
Private Sub SpinButton1_SpinUp()

    If varNClick = varNClick2 Then
        varNClick = varNClick + 1
    Else
        varNClick2 = varNClick2 + 1
    End If
    varString = "RH" & Format(varNClick, "00000") & "-" & _
                           Format(varNClick2, "00")
    MsgBox (varString)
    
End Sub

Private Sub Worksheet_Activate()
    
    MsgBox ("RH00000-00")
    varNClick = 0
    varNClick2 = 0
    
End Sub
 
Upvote 0
Yes, but take care where you will put initial values.
It may be event "Workbook_Open" or Worksheet_Activate instead UserForm_Initialize.
Example...
VBA Code:
Option Explicit

Dim varString As String
Dim varNClick, varNClick2

Private Sub SpinButton1_SpinUp()

    If varNClick = varNClick2 Then
        varNClick = varNClick + 1
    Else
        varNClick2 = varNClick2 + 1
    End If
    varString = "RH" & Format(varNClick, "00000") & "-" & _
                           Format(varNClick2, "00")
    MsgBox (varString)
   
End Sub

Private Sub Worksheet_Activate()
   
    MsgBox ("RH00000-00")
    varNClick = 0
    varNClick2 = 0
   
End Sub
Also, is it possible for the numbers to be displayed using a TextBox instead of a message box? Would I just do TextBox1.Text = varString?
 
Upvote 0
Maybe this...

VBA Code:
With SpinButton1
    .SmallChange = 1
    TextBox8.Text = "RH" & Format(.Value / 2, "00000") & Format(Application.Max((.Value - 1), 0) / 2, "-00")
End With
 
Upvote 0
Solution
Maybe this...

VBA Code:
With SpinButton1
    .SmallChange = 1
    TextBox8.Text = "RH" & Format(.Value / 2, "00000") & Format(Application.Max((.Value - 1), 0) / 2, "-00")
End With
This works, sorry for the delay, I forgot to mark as new, as I'm still kind of new to this.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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