title: Excel VBA: Auto Increment ID Number inside of Text
body: <p>I have here the sample code of how the auto increment ID Number and sample output of the program</p>
  
  <p><a href="https://i.stack.imgur.com/OOekw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OOekw.png" alt="enter image description here"></a></p>
  
  <pre><code>Sub AddData()
  Dim ws As Worksheet 'define worksheet
  Set ws = ThisWorkbook.Worksheets("Sheet3")
  
  Dim Deadline As Range 'define deadline range
  Set Deadline = ws.Range("H1")
  
  Dim Submitted As Range 'define submitted range
  Set Submitted = ws.Range("H3")
  
  
  Dim nRow As Long 'find next free row = last used used row +1
  nRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
  
  ws.Cells(nRow, "A").Value = "ABC-00" &amp; nRow &amp; ""
  ws.Cells(nRow, "B").Value = Deadline.Value
  ws.Cells(nRow, "C").Value = Submitted.Value
  End Sub
  </code></pre>
  
  <p>As you can see, I have 3 different fields. ID, DEADLINE, SUBMITTED</p>
  
  <p>Whenever I enter a new record for deadline and submitted field the id should automatically increment based on the last inserted id.</p>
  
  <p>As you notice, the first ID is ABC-001 and It suddenly jump into ABC-003 instead of ABC-002.</p>
  
  <p>As I guess maybe the reason is, it follows the row # of the data that's why after ABC-001 it shows up as ABC-003 because this ID number is row #3</p>
  
  <p>Is there any way to get the last inserted ID and be a basis for generating new id?</p>