title: Copy data from one table and Clear and update new data into another table in another sheet in excel 2010
body: <p>I have a VBA macro which is currently copying data from Setup sheet and updating into the respective tables into Read_Only sheet for the first time. But when I click second time, it is adding the data into the respective tables in Read_Only sheet.</p>
  
  <p>Now what I want is, if I click second time, it should first clear the existing data from that respective table in Read_Only sheet and then update the new data into that table. (For example: In 1st table, there were 10 rows of data, now when I click 2nd time I have only 8 rows of data, then macro should clear data existing 10 rows of data and update this new 8 rows of data and then delete the 2 empty two rows. This should be Dynamic, since number of rows may vary every time while updating new data)</p>
  
  <p>Here is the existing code: </p>
  
  <pre><code>Sub copyData()
  
      Dim wsSet As Worksheet
      Dim wsRead As Worksheet
      Dim rngSearch As Range
      Dim lastRow As Integer
      Dim i As Integer
      Dim wRow As Integer
      Dim strCat As String
      Dim catRow As Integer
  
      Set wsSet = ActiveWorkbook.Worksheets("Budget_Setup")
      Set wsRead = ActiveWorkbook.Worksheets("WBS_Overview_Read_only")
      Set rngSearch = wsRead.Range("A12:A1000")    'range in READ to search for category
      lastRow = wsSet.Range("B16").End(xlDown).Row     'last row of data in SET
  
      Application.ScreenUpdating = False
  
      For i = 17 To lastRow
          strCat = Left(wsSet.Range("b" &amp; i).Value, 3)    'current category in SET
          catRow = rngSearch.Find(strCat).Row             'row of match in READ
          If wsRead.Range("a" &amp; catRow + 1).Value = "" Then   'find the correct row to copy into
              wRow = catRow + 1
          Else
              wRow = wsRead.Range("a" &amp; catRow).End(xlDown).Row + 1
              If wsRead.Range("e" &amp; wRow).Value &lt;&gt; "" Then
                  wsRead.Range("a" &amp; wRow).EntireRow.Insert
              End If
          End If
          wsSet.Range("b" &amp; i &amp; ":f" &amp; i).Copy
          wsRead.Range("a" &amp; wRow).PasteSpecial
          Application.CutCopyMode = False
      Next i
  
      Application.ScreenUpdating = True
  
      Set wsRead = Nothing
      Set wsSet = Nothing
  End Sub
  </code></pre>