lisatylr70
New Member
- Joined
- Feb 22, 2018
- Messages
- 2
Hello. I am fairly new to VBA. I have a workbook with over 50 active sheets, each sheet could have different number of rows. I need to create a Macro to search through the majority of the sheets (some sheets are excluded) and if column T is >90 then copy columns A and T into a Summary sheet.
I need the macro to clear the contents of the summary sheet before pasting, and remove duplicates of column A in the summary sheet after pasting. I have researched several forums and come up with the below code, but this code copies the entire row and I can't quite figure out how to clear the contents of the summary sheet and remove the duplicates. I am using Excel 2016. Any help with this would be greatly appreciated.
Sub CopyOverstock()
Dim wsSum As Worksheet: Set wsSum = Sheets("OverStock Summary")
Dim ws As Worksheet
Dim rCell As Range
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For Each ws In Worksheets
If ws.Name <> wsSum.Name And ws.Name <> "OH Inv" And ws.Name <> "Usage SS" And ws.Name <> "Open POs" And ws.Name <> "Sheet1" And ws.Name <> "Potential GAPs" And ws.Name <> "Transfers" Then
For Each rCell In ws.Range("t4:t" & ws.Range("t" & Rows.count).End(xlUp).Row)
If rCell.Value <> "" And IsNumeric(rCell.Value) Then
If rCell.Value > 20 Then
rCell.EntireRow.Copy
wsSum.Cells(Rows.count, 1).End(xlUp)(2).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End If
Next rCell
End If
Next ws
Application.CutCopyMode = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
I need the macro to clear the contents of the summary sheet before pasting, and remove duplicates of column A in the summary sheet after pasting. I have researched several forums and come up with the below code, but this code copies the entire row and I can't quite figure out how to clear the contents of the summary sheet and remove the duplicates. I am using Excel 2016. Any help with this would be greatly appreciated.
Sub CopyOverstock()
Dim wsSum As Worksheet: Set wsSum = Sheets("OverStock Summary")
Dim ws As Worksheet
Dim rCell As Range
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For Each ws In Worksheets
If ws.Name <> wsSum.Name And ws.Name <> "OH Inv" And ws.Name <> "Usage SS" And ws.Name <> "Open POs" And ws.Name <> "Sheet1" And ws.Name <> "Potential GAPs" And ws.Name <> "Transfers" Then
For Each rCell In ws.Range("t4:t" & ws.Range("t" & Rows.count).End(xlUp).Row)
If rCell.Value <> "" And IsNumeric(rCell.Value) Then
If rCell.Value > 20 Then
rCell.EntireRow.Copy
wsSum.Cells(Rows.count, 1).End(xlUp)(2).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End If
Next rCell
End If
Next ws
Application.CutCopyMode = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub