title: Run-time error '1004': Application-defined or object-defined error .Cells
body: <p>I'm just trying to code a macro to delete certain rows where the cells in Column A equal specific text, but I'm receiving a 1004 error which highlights the line <strong>'If .Cells(rowData, 1).Value = "IN" Then'</strong></p>
  
  <p>I had a few issues prior to this that I managed to correct thanks to VBA's errors giving explanations of the problems but I've gotten a bit stuck on this one - sorry for my inexperience</p>
  
  <pre><code>Option Explicit
  
  Sub Test()
  Dim csvWorksheet As Worksheet
  Dim rowData As Long
  Dim rData As Range
  
      'DELETE ANY 'IN' ROWS
      With Worksheets("Movers_detail")
          If .Cells(rowData, 1).Value = "IN" Then
              .Rows(rowData).EntireRow.Delete
          End If
          End With
  
  
  Set rData = csvWorksheet.Cells(1, 1).CurrentRegion
  With rData
      .EntireColumn.AutoFit
  
      'draw border
      .Borders(xlDiagonalDown).LineStyle = xlNone
      .Borders(xlDiagonalUp).LineStyle = xlNone
      With .Borders(xlInsideVertical)
          .LineStyle = xlContinuous
          .ColorIndex = 0
          .TintAndShade = 0
          .Weight = xlThin
      End With
      With .Borders(xlInsideHorizontal)
          .LineStyle = xlContinuous
          .ColorIndex = 0
          .TintAndShade = 0
          .Weight = xlThin
      End With
      With .Borders(xlEdgeLeft)
          .LineStyle = xlContinuous
          .ColorIndex = 0
          .TintAndShade = 0
          .Weight = xlMedium
      End With
      With .Borders(xlEdgeTop)
          .LineStyle = xlContinuous
          .ColorIndex = 0
          .TintAndShade = 0
          .Weight = xlMedium
      End With
      With .Borders(xlEdgeBottom)
          .LineStyle = xlContinuous
          .ColorIndex = 0
          .TintAndShade = 0
          .Weight = xlMedium
      End With
      With .Borders(xlEdgeRight)
          .LineStyle = xlContinuous
          .ColorIndex = 0
          .TintAndShade = 0
          .Weight = xlMedium
      End With
  End With
  
  'formatting the cell alignment
  Columns("A:C").Select
  With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlCenter
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
  End With
  
  'formatting the page scaling for printing
  Application.PrintCommunication = False
  With ActiveSheet.PageSetup
      .PrintTitleRows = ""
      .PrintTitleColumns = ""
  End With
  Application.PrintCommunication = True
  ActiveSheet.PageSetup.PrintArea = ""
  Application.PrintCommunication = False
  With ActiveSheet.PageSetup
      .LeftHeader = ""
      .CenterHeader = ""
      .RightHeader = ""
      .LeftFooter = ""
      .CenterFooter = ""
      .RightFooter = ""
      .LeftMargin = Application.InchesToPoints(0.7)
      .RightMargin = Application.InchesToPoints(0.7)
      .TopMargin = Application.InchesToPoints(0.75)
      .BottomMargin = Application.InchesToPoints(0.75)
      .HeaderMargin = Application.InchesToPoints(0.3)
      .FooterMargin = Application.InchesToPoints(0.3)
      .PrintHeadings = False
      .PrintGridlines = False
      .PrintComments = xlPrintNoComments
      .PrintQuality = 600
      .CenterHorizontally = True
      .CenterVertically = False
      .Orientation = xlPortrait
      .Draft = False
      .PaperSize = xlPaperA4
      .FirstPageNumber = xlAutomatic
      .Order = xlDownThenOver
      .BlackAndWhite = False
      .Zoom = False
      .FitToPagesWide = 1
      .FitToPagesTall = 20
      .PrintErrors = xlPrintErrorsDisplayed
      .OddAndEvenPagesHeaderFooter = False
      .DifferentFirstPageHeaderFooter = False
      .ScaleWithDocHeaderFooter = True
      .AlignMarginsHeaderFooter = True
      .EvenPage.LeftHeader.Text = ""
      .EvenPage.CenterHeader.Text = ""
      .EvenPage.RightHeader.Text = ""
      .EvenPage.LeftFooter.Text = ""
      .EvenPage.CenterFooter.Text = ""
      .EvenPage.RightFooter.Text = ""
      .FirstPage.LeftHeader.Text = ""
      .FirstPage.CenterHeader.Text = ""
      .FirstPage.RightHeader.Text = ""
      .FirstPage.LeftFooter.Text = ""
      .FirstPage.CenterFooter.Text = ""
      .FirstPage.RightFooter.Text = ""
  End With
  Application.PrintCommunication = True
  
  
  End Sub
  </code></pre>