title: Automatically change numeration in Excel
body: <p>I have an Excel Worksheet and the column A should be automatically numerized between A4 and ~A50 (depends on how many clients there are, but normally it's around 41 - 43, maximum 45) when I add a new row.</p>
  
  <p>For example: A4 has the value 1, A5 has 2, A6 has 3, etc. until A43 which has the value 40. I want to add a new row somewhere in between and the numbers should change accordingly... Also, the number of total clients has increased, so the cell A44 shoud now hold the new number 41.</p>
  
  <p>I searched Google and found out, that I had to write a VB macro for that (is that true, can't that be solved in an easier way? Excel is so mighty powerful, but it can't do that?) and it works somewhat. However, when I do try to add a new row, it doesn't behave correctly, the numbers at the end of the table get messed up a bit and it doesn't count correctly:</p>
  
  <p><a href="https://i.stack.imgur.com/UNzcy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UNzcy.png" alt="Excel numeration problem"></a></p>
  
  <p>It's always in the same area, the number 38 doesn't switch to 39. Unfortunately, my VB skills are very limited, and they already were 5 years ago, when I last used it. Here's the script:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  
      Dim cntClients As Integer
      Dim lastCell As Integer
      Dim startNum As Integer
      Dim startRow As Integer
  
      cntClients = WorksheetFunction.CountA(Range("A4:A60"))
      lastCell = cntClients + 3
      startNum = 1
      startRow = 4
  
      Application.EnableEvents = False
      Do While startRow &lt;= cntClients
          Range("A" &amp; startRow).Value = startNum
          startRow = startRow + 1
          startNum = startNum + 1
      Loop
      Range("A" &amp; lastCell) = cntClients
      Application.EnableEvents = True
  
  End Sub
  </code></pre>
  
  <p>I hope I got my point accross clearly and if there's an easier solution for this problem, one that potentially does not use macros, please let me know!</p>
  
  <p>If you need any further information, I'll gladly provide them!</p>
  
  <p>EDIT: Also, when I delete the newly added row, the numbers don't change correctly either, like here:</p>
  
  <p><a href="https://i.stack.imgur.com/KqF8N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KqF8N.png" alt="Excel problem 2"></a></p>
  
  <p>Somehow the macro does not like the number 39</p>