ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 857
- Office Version
- 365
- 2019
- Platform
- Windows
Would someone be able to help me come up with a VBA code to delete all the rows where its cell value in column P = 1 but ignoring the first row of data (P2) seeing that is where the formula resides. Below is a snipbit of the code where I would need it.
VBA Code:
With Worksheets(SheetName)
lr1 = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("M1:Q1") = Array("Rounded 2 digit Unit Cost", "Greater than 1yr", "Greater than 3yr", "For formula", "Same Occurrence")
.Application.Calculation = xlAutomatic
.Range("P2:P" & lr1).NumberFormat = "General"
.Range("M2:M" & lr1).Formula = "=Round(K2, 2)"
.Range("N2:N" & lr1).Formula = "=if(RUN-E2>365,""YES"",""NO"")"
.Range("O2:O" & lr1).Formula = "=if(RUN-E2>(365*3),""YES"",""NO"")"
If TFLG = "N" Then
.Range("P2:P" & lr1).Formula = "=D2&M2"
Else
.Range("P2:P" & lr1).Formula = "=D2&E2&M2"
End If
.Range("P2:P" & lr1).NumberFormat = "@"
.Range("Q2").Formula2 = "=COUNTIF($P$2:$P$" & lr1 & ",$P$2:$P$" & lr1 & ")" 'need alternative takes too long
'.Range("P2").Formula2 = "=COUNTIFS($D$2:$D$" & lr1 & ",$D$2:$D$" & lr1 & ",$M$2:$M$" & lr1 & ",$M$2:$M$" & lr1 & ")" 'combines matching and countif could help speed?
.Range("M2:P" & lr1).Value = .Range("M2:P" & lr1).Value
.Range("1:1").AutoFilter
.Cells.EntireColumn.AutoFit
.Activate
End With