Forum Discussion
Suzanne25811
May 13, 2022Copper Contributor
is there a way to make sure my macro doesn't duplicate data
I posted in another blog and haven't received a response so I am not sure that what I am asking can be done. I used code from the following article https://docs.microsoft.com/en-us/office/vba/api/e...
- May 16, 2022
Subodh_Tiwari_sktneer
May 14, 2022Silver Contributor
Please give this a try and see if this works for you...
Sub CopyRows()
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim shArr As Variant
Dim sh As Variant
Dim FinalRow As Long
Dim NextRow As Long
Application.ScreenUpdating = False
Set wsSource = ThisWorkbook.Worksheets("MORSE Item Sales Analysis")
wsSource.AutoFilterMode = False
FinalRow = wsSource.Cells(Rows.Count, 1).End(xlUp).Row
shArr = Array("FORN", "GRLK", "NEST", "NWST", "PLNS")
With wsSource.Range("A1").CurrentRegion
For Each sh In shArr
.AutoFilter field:=29, Criteria1:=sh
If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
Set wsDest = ThisWorkbook.Worksheets(sh)
wsDest.Range("A1").CurrentRegion.Offset(1).ClearContents
wsSource.Range("A2:AB" & FinalRow).SpecialCells(xlCellTypeVisible).Copy wsDest.Range("A2")
End If
Next sh
End With
wsSource.AutoFilterMode = False
Application.ScreenUpdating = True
MsgBox "Task Completed!", vbInformation
End Sub- Suzanne25811May 16, 2022Copper Contributor
Subodh_Tiwari_sktneer thank you for your help. Do I insert this after all of the code I showed in my message or do I need to insert this for each section I reference in the code? Once I know what to do with it, I will follow up to let you know how it works.
I appreciate you!
- Subodh_Tiwari_sktneerMay 16, 2022Silver Contributor
- Suzanne25811May 16, 2022Copper ContributorIt worked in my test file!!! Thank you SO much!!!