title: Type Mismatch error trying to move data to various worksheets
body: <p>I am trying to move data from a worksheet called Raw_Data to various other worksheets based on values in column A. I'm getting a type mismatch when finding the last row in the target worksheet. Does <code>.worksheets().cells().end().row</code> not return a number? I've noted the line where the "type mismatch" error is being thrown. Here's the code:</p>
  
  <pre><code>Sub MoveDataToWorksheet()
  
  Dim i As Variant
  Dim pname As String
  Dim rng As Range
  Dim lastrow As Long
  Dim wslastrow As Long
  Dim ws As Worksheet
  Dim count As Long
  Dim rawdata As Worksheet
  
  Set rawdata = ThisWorkbook.Worksheets("Raw_Data")
  lastrow = rawdata.Cells(Rows.count, "a").End(xlUp).Row
  Set rng = rawdata.Range("a5:a" &amp; lastrow)
  
  For Each ws In ThisWorkbook.Worksheets
      If ws.Name = "Raw_Data" Or ws.Name = "Charts" Or _
      ws.Name = "Tables" Then
      'skips the sheets I want to keep
      Else
          wslastrow = ws.Cells(Rows.count, "a").End(xlUp).Row
          If wslastrow &gt;= 5 Then
              ws.Range("a5:r" &amp; wslastrow).Delete
          Else
              ws.Range("a5:r" &amp; 6).Delete
          End If
      End If
  Next ws
  
  For Each i In rng
      pname = Cells(i.Row, "a").Value
  
      For Each ws In ThisWorkbook.Worksheets
          If pname = ws.Name Then
              wslastrow = ws.Cells(Rows.count, "a").End(xlUp).Row
              i.EntireRow.Copy
              ws.Cells(wslastrow, "a").PasteSpecial
          End If
      Next ws
  
          If pname = "South Carolina" Then
              i.EntireRow.Copy
              wslastrow = ThisWorkbook.Worksheets(SC).Cells(Rows.count, "a").End(xlUp).Row + 1
              ThisWorkbook.Worksheets(SC).Cells(wslastrow, "a").PasteSpecial
          End If
  
          If pname = "Saudi Arabia" Then
              i.EntireRow.Copy
              wslastrow = ThisWorkbook.Worksheets(KSA).Cells(Rows.count, "a").End(xlUp).Row + 1    'Error on this line but I imagine it will also be on the other wslastrow lines too.
              ThisWorkbook.Worksheets(KSA).Cells(wslastrow, "a").PasteSpecial
          End If
  
          If pname = "United Arab Emerites" Then
              i.EntireRow.Copy
              wslastrow = ThisWorkbook.Worksheets(UAE).Cells(Rows.count, "a").End(xlUp).Row + 1
              ThisWorkbook.Worksheets(UAE).Cells(wslastrow, "a").PasteSpecial
          End If
  Next i
  
  'code to fix formulas
  End Sub
  </code></pre>