Hi,
I am trying this code in my excel but i am getting error.
What i want to do i have 4 option button AFBB , HOMES , WOVEN ,HARDGOODS and i would like to select starting 4 Character of buttons and generate Unique ID with date but i am unable to this
can you please help me?
I am trying this code in my excel but i am getting error.
What i want to do i have 4 option button AFBB , HOMES , WOVEN ,HARDGOODS and i would like to select starting 4 Character of buttons and generate Unique ID with date but i am unable to this
can you please help me?
Code:
Private Sub CommandButton1_Click()
Dim Rng As Range, Dn As Range, n As Long
Dim pType As String
Dim oMax As Long
Dim datee As Date
datee = Format(Date, "dd-mm-yyyy")
Set Rng = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
Const StartNum = 10000
For n = 1 To 4
With Me.Controls("OptionButton" & n).Object
If .Value = True Then
pType = Left(.Caption, 3)
Exit For
End If
End With
Next
If pType = vbNullString Then MsgBox "Please Select Option Button": Exit Sub
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Right(Dn.Value, 1) = pType Then
If Not .Exists(Dn.Value) Then
.Add Dn.Value, Mid(Dn, 2)
oMax = Application.Max(.Item(Dn.Value), Mid(Dn, 2))
Else
MsgBox "Number Exists:-" & Dn.Value
End If
End If
Next
If .Count = 0 Then
Range("B" & Rng.Count + 1) = pType & StartNum & datee
Else
Range("B" & Rng.Count + 1) = pType & oMax + Rng & datee
End If
End With
End Sub
Last edited by a moderator: