Hello
I want changing the character when autonumbering in textbox based on optionbutton selection
the current code will show word "BGH-" & date based on this line
but now I want changing to
it depends on optionbutton name selection and the optionbutton name will match with sheet name where auto numbering for each sheet alone
when autonumbering in textbox will write the optionbutton name selection for instance SALES & NO 0004300 to become SALES NO 0004300 as in the picture above
and copy to sheet name is matched with optionbutton name selection in A1 cell and when click command button1 will increase the number like this
and if I click commandbutton2 then will decrease number like this
and if select PURCHASE will be like SALES for instance PURCHASE NO 0004300 but the the only different is OPTIONBUTTON NAME and should copy to sheet name into cell A1 is matched with optionbutton name
here is the whole codes
I hope from the experts give me some help.
I want changing the character when autonumbering in textbox based on optionbutton selection
the current code will show word "BGH-" & date based on this line
VBA Code:
.Value = "BGH-" & Format$(Date, "mm-dd-1")
it depends on optionbutton name selection and the optionbutton name will match with sheet name where auto numbering for each sheet alone
when autonumbering in textbox will write the optionbutton name selection for instance SALES & NO 0004300 to become SALES NO 0004300 as in the picture above
and copy to sheet name is matched with optionbutton name selection in A1 cell and when click command button1 will increase the number like this
and if I click commandbutton2 then will decrease number like this
and if select PURCHASE will be like SALES for instance PURCHASE NO 0004300 but the the only different is OPTIONBUTTON NAME and should copy to sheet name into cell A1 is matched with optionbutton name
here is the whole codes
VBA Code:
Option Explicit
Private flg As Boolean
Private Sub UserForm_Initialize()
Dim x
With Sheets("SALES").[a1]
flg = .Value = ""
If flg Then
.Value = "BGH-" & Format$(Date, "mm-dd-1")
Me.TextBox1 = .Value
Else
x = Split(Sheets("SALES").[a1], "-")
x(UBound(x)) = x(UBound(x))
.Value = Join(x, "-")
Me.TextBox1 = .Value
End If
Me.Tag = .Value
End With
Me.CommandButton1.Enabled = Not flg
End Sub
Private Sub CommandButton1_Click()
Dim x
With Sheets("SALES").[a1]
If Not flg Then
x = Split(Sheets("SALES").[a1], "-")
x(UBound(x)) = x(UBound(x)) + 1
.Value = Join(x, "-")
Me.TextBox1 = .Value
End If
End With
End Sub
Private Sub CommandButton2_Click()
If Me.TextBox1 = Me.Tag Then Exit Sub
Dim x
With Sheets("SALES").[a1]
If Not flg Then
x = Split(Sheets("SALES").[a1], "-")
x(UBound(x)) = x(UBound(x)) - 1
.Value = Join(x, "-")
Me.TextBox1 = .Value
End If
End With
End Sub
I hope from the experts give me some help.