Increasing numbers in a Log

xOsnailx

New Member
Joined
Sep 7, 2017
Messages
6
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! :)
 
What's difference is between this code and mine :
Your code generates duplicate numbers. When AP1000 is reached your code generates AP101, AP102 and so on.
BTW, I couldn't reproduce the run-time errors the OP was experiencing.
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
@GWteB how should mod the code ? if there is button cancel for instance from the first time . it will save AP1 and if I run again it will increment to become AP2 but if I press cancel , then should clear AP2 and keep AP1 , if incerment and I press cancel should clear not save . any ideas?
 
Upvote 0
@MKLAQ , would suggest to have an additional macro to revert the previous increase.
VBA Code:
Private Sub MKLAQ()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Data")
    With ws
        iRow = .Cells(.Rows.Count, "F").End(xlUp).Row
        .Range("F" & iRow).Value = ""
        iRow = .Cells(.Rows.Count, "F").End(xlUp).Row
        RefNo.Text = .Range("F" & iRow).Value
    End With
End Sub
 
Upvote 0
wow ! you're super great !
thanks so much professional;)
 
Upvote 0
You're welcome and thanks for the feedback (y)
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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