edgarmalroy
New Member
- Joined
- Jul 13, 2024
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
Hello all!
I hope you can help. I have created a userform for data entry and is working well. I am hoping that I can add something that generates a unique code for each entry and add that.
So I have a table like below and a userform that populates everything from name onwards. I would like each submission on the form to also generate a unique client code, ideally based on the first letter +1 of the name and the number of row, as per below - is this possible? Many thanks
Current code:
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Clients")
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
With ws
.Cells(iRow, 2).Value = Me.txtname.Value
.Cells(iRow, 3).Value = Me.txtdate.Value
.Cells(iRow, 4).Value = Me.cbtype.Value
.Cells(iRow, 5).Value = Me.cbtherapist.Value
.Cells(iRow, 6).Value = Me.txtfee.Value
.Cells(iRow, 7).Value = Me.txtphone.Value
.Cells(iRow, 8).Value = Me.txtemail.Value
.Cells(iRow, 9).Value = Me.txtadd1.Value
.Cells(iRow, 10).Value = Me.txtadd2.Value
.Cells(iRow, 11).Value = Me.txtcity.Value
.Cells(iRow, 12).Value = Me.txtpostcode.Value
.Cells(iRow, 13).Value = Me.txtgp.Value
.Cells(iRow, 14).Value = Me.cbhealth.Value
.Cells(iRow, 15).Value = Me.txthdetails.Value
.Cells(iRow, 16).Value = Me.txtemerg.Value
.Cells(iRow, 17).Value = Me.cbmeds.Value
.Cells(iRow, 18).Value = Me.txtmdetails.Value
End With
'clear the data
Me.txtname.Value = ""
Me.txtdate.Value = ""
Me.cbtype.Value = ""
Me.cbtherapist.Value = ""
Me.txtfee.Value = ""
Me.txtphone.Value = ""
Me.txtemail.Value = ""
Me.txtadd1.Value = ""
Me.txtadd2.Value = ""
Me.txtcity.Value = ""
Me.txtpostcode.Value = ""
Me.txtgp.Value = ""
Me.cbhealth.Value = ""
Me.txthdetails.Value = ""
Me.txtemerg.Value = ""
Me.cbmeds.Value = ""
Me.txtmdetails.Value = ""
End Sub
I hope you can help. I have created a userform for data entry and is working well. I am hoping that I can add something that generates a unique code for each entry and add that.
So I have a table like below and a userform that populates everything from name onwards. I would like each submission on the form to also generate a unique client code, ideally based on the first letter +1 of the name and the number of row, as per below - is this possible? Many thanks
Client Code | Name | Start Date | Client Type | Psychotherapist |
N001 | Martin Stevenson | 34/23/4234 | x | x |
C002 | Bob Mortimer | 34/23/123 | x | x |
Current code:
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Clients")
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
With ws
.Cells(iRow, 2).Value = Me.txtname.Value
.Cells(iRow, 3).Value = Me.txtdate.Value
.Cells(iRow, 4).Value = Me.cbtype.Value
.Cells(iRow, 5).Value = Me.cbtherapist.Value
.Cells(iRow, 6).Value = Me.txtfee.Value
.Cells(iRow, 7).Value = Me.txtphone.Value
.Cells(iRow, 8).Value = Me.txtemail.Value
.Cells(iRow, 9).Value = Me.txtadd1.Value
.Cells(iRow, 10).Value = Me.txtadd2.Value
.Cells(iRow, 11).Value = Me.txtcity.Value
.Cells(iRow, 12).Value = Me.txtpostcode.Value
.Cells(iRow, 13).Value = Me.txtgp.Value
.Cells(iRow, 14).Value = Me.cbhealth.Value
.Cells(iRow, 15).Value = Me.txthdetails.Value
.Cells(iRow, 16).Value = Me.txtemerg.Value
.Cells(iRow, 17).Value = Me.cbmeds.Value
.Cells(iRow, 18).Value = Me.txtmdetails.Value
End With
'clear the data
Me.txtname.Value = ""
Me.txtdate.Value = ""
Me.cbtype.Value = ""
Me.cbtherapist.Value = ""
Me.txtfee.Value = ""
Me.txtphone.Value = ""
Me.txtemail.Value = ""
Me.txtadd1.Value = ""
Me.txtadd2.Value = ""
Me.txtcity.Value = ""
Me.txtpostcode.Value = ""
Me.txtgp.Value = ""
Me.cbhealth.Value = ""
Me.txthdetails.Value = ""
Me.txtemerg.Value = ""
Me.cbmeds.Value = ""
Me.txtmdetails.Value = ""
End Sub