I am running a macro that takes data from a master sheet and copies it to an individual sheet. Each time the macro runs it duplicates the data. I need it to clear the data from the sheet each time before it runs. I am using code below.
Sub Master()
Dim x As Long, srcWks As Worksheet, destWks As Worksheet, rngData As Range, rng As Range
Const str1 As String = "Pole Transfer"
Set srcWks = Sheets("Master") 'Source sheet
Set destWks = Sheets("Pole Transfer") 'Destination sheet
Application.ScreenUpdating = False
With srcWks
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 1).End(xlUp).Row
Set rngData = .Range("A1", "M" & x)
rngData.AutoFilter field:=2, Criteria1:=str1
With Range("A1").CurrentRegion
.Offset(1).Copy
End With
With destWks.Range("A" & Rows.Count).End(xlUp).Offset(1)
.PasteSpecial Paste:=xlValues
End With
.AutoFilterMode = False
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Bookmarks