title: Add unique number to excel datasheet using VBA
body: <p>I have two columns of numbers, together they will be unique (composite key). I would like to create an unique ID number (third column) similar to how MS Access would use a primary key. I would like to do this in VBA but I am stuck on how to do it.</p>
  
  <p>My VBA in excel isn't very good so hopefully you can see what I've started to attempt. it may be completely wrong... I don't know?</p>
  
  <p>I don't know how to make the next concatenation and I am unsure about how to go down to the next row correctly. </p>
  
  <pre><code>Sub test2()
  
  Dim var As Integer
  Dim concat As String
  
  concat = Range("E2").Value &amp; Range("F2").Value
  
  var = 1
  
  'make d2 activecell
  Range("D2").Select
  
  Do Until concat = ""
      'if the concat is the same as the row before we give it the same number
      If concat = concat Then
          var = var
      Else
          var = var + 1
      End If
      ActiveCell.Value = var
      ActiveCell.Offset(0, 1).Select
      'make the new concatination of the next row?
  Loop
  End Sub
  </code></pre>
  
  <p>any help is appreciated, thanks. </p>