title: Can not find last row on a separate worksheet in excel
body: <p>I am currently working on a macro and I had it working 100% like I wanted, but when I went to move the control group to a different sheet, I've started getting all sorts of problems. Here is the code:</p>
  
  <pre><code>Sub Duplicate_Count()
  
  'Diclare Variables
  Dim LastRow As Long
  Dim value1 As String
  Dim value2 As String
  Dim counter As Long
  Dim startRange As Long
  Dim endRange As Long
  Dim inColumn As String
  Dim outColumn As String
  Dim color As Long
  counter = 0
  Dim sht As Worksheet
  Dim controlSht As Worksheet
  Set sht = Worksheets("Sheet1")
  Set controlSht = Worksheets("Duplicate Check")
  
  'Find the last used row in column L
  LastRow = sht.Cells(Rows.Count, "L").End(xlUp).Row
  
  'set default ranges
  startRange = 2
  endRange = LastRow - 1
  inColumn = "L"
  outColumn = "N"
  
  'check for user inputs
  If controlSht.Cells(8, "B") &lt;&gt; "" Then
      startRange = controlSht.Cells(8, "B")
  End If
  If controlSht.Cells(8, "C") &lt;&gt; "" Then
      endRange = controlSht.Cells(8, "C")
  End If
  If controlSht.Cells(11, "C") &lt;&gt; "" Then
      Column = controlSht.Cells(11, "C")
  End If
  If controlSht.Cells(14, "C") &lt;&gt; "" Then
      Column = controlSht.Cells(14, "C")
  End If
  color = controlSht.Cells(17, "C").Interior.color
  
  'Search down row for duplicates
  Dim i As Long
  
  For i = startRange To endRange
  
      'Sets value1 and value2 to be compared
      value1 = sht.Cells(i, inColumn).Value
      value2 = sht.Cells(i + 1, inColumn).Value
  
      'If values are not diferent then counter will not increment
      counter = 1
  
      Do While value1 = value2
          sht.Cells(i, inColumn).Interior.color = color
          sht.Cells(i + counter, inColumn).Interior.color = color
          counter = counter + 1
          value2 = sht.Cells(i + counter, inColumn).Value
      Loop
  
      'Ouput the number of duplicates on last duplicates row
      If counter &lt;&gt; 1 Then
          sht.Cells(i + counter - 1, outColumn) = counter
          i = i + counter - 1
      End If
  
  Next i
  
  End Sub
  </code></pre>
  
  <p>This is my first program so I apologize for all the mistakes. This code does exactly what I want except for finding the last row if there is no user input. It always says the last row is 1, when it should be 110460. I'm not sure if it's grabbing from the wrong sheet or if there is an error in my logic.</p>