Hi - I have been trying to create a log to track referrals using Excel User Forms - 95% works fine apart from the part where I try to get it to create a unique ref (+1 on the last one). All I get is the same ref each time I try to create a new record, regardless of how many times I try. The ref is logged in Column F of the Data tab. I have a form which other information is added, then a button to save that into the sheet. I also have a text box (named 'RefNo') on the form to show the new ref, butu each time I get AP1, AP1, AP1..
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")
RefNo.Enabled = True
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
If ws.Range("F" & iRow).Value = "" Then
RefNo.Text = "AP1"
ws.Range("F" & iRow).Value = RefNo
Else
RefNo.Text = "AP" & Val(Mid(ws.Cells(iRow, 1).Value, 1)) + 1
ws.Range("F" & iRow + 1).Value = RefNo
End If
Can anyone see anything obviously wrong? Many thanks!
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")
RefNo.Enabled = True
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
If ws.Range("F" & iRow).Value = "" Then
RefNo.Text = "AP1"
ws.Range("F" & iRow).Value = RefNo
Else
RefNo.Text = "AP" & Val(Mid(ws.Cells(iRow, 1).Value, 1)) + 1
ws.Range("F" & iRow + 1).Value = RefNo
End If
Can anyone see anything obviously wrong? Many thanks!