title: How to get last column used in excel using vba
body: <p>Hi I am having issues getting to the last column used in my sheet. </p>
  
  <p>I do know that as it stands my last column is 43 and i want it to enter a value at column 44, so then when i search again it will go to column 44 as last column used and then enter a value at 45 and so on and so on. I am using a ref num to find the correct row.</p>
  
  <p>The code I am using is as follows to try get the last column </p>
  
  <pre><code>'find last empty Col in database
  LastCol = sou.Cells(2, Columns.count).End(xlToLeft).Column + 1
  MsgBox LastCol
  
  'For Loop to cycle through the columns
  For x = 2 To LastCol
  
      'If the row value at column 1 = the ref number then continue
      If sou.Cells(x, 1).Value = refNum Then
          sou.Cells(x, LastCol).Value = Me.commentBox.Text
          Exit For
      End If
  
  Next
  </code></pre>
  
  <p>The issue is that for some reason it only goes to column 22. I have tried to use the other ways to get the last column but they have just given me the last column in the whole entire sheet which again is not what I want. </p>
  
  <p>If someone can lend me a hand as I'm a newbie to this it would be greatly appreciated!</p>