Clear data before updating

Abdulkhadar

Board Regular
Joined
Nov 10, 2013
Messages
165
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello Excel Experts,
I want to add a code to clear all sheets data except sheet main (Sheet Name) from 4th row to last used row before updating the sheets in below VBA.

VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim bottomA As Long
    bottomA = Range("F" & Rows.Count).End(xlUp).Row
    Dim AccNum As Range
    For Each AccNum In Range("F4:F" & bottomA)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) = AccNum.Offset(0, -4)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = AccNum.Offset(0, -3)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "C").End(xlUp).Offset(1, 0) = AccNum.Offset(0, -2)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "D").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 1)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "E").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 3)
    Next AccNum
    Application.ScreenUpdating = True
End Sub


Thanks in advance
 
Last edited by a moderator:
If this is still basically the same issue as it was 3 years ago except only 5 columns and starting at row 5 instead of row 4 then try

Rich (BB code):
If ws.Name <> "main" And ws.Name <> "RP" Then ws.UsedRange.Offset(4).Resize(, 5).ClearContents
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
If this is still basically the same issue as it was 3 years ago except only 5 columns and starting at row 5 instead of row 4 then try

Rich (BB code):
If ws.Name <> "main" And ws.Name <> "RP" Then ws.UsedRange.Offset(4).Resize(, 5).ClearContents
Thanks once again for your quick response........:biggrin::biggrin::biggrin::biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top