Delete Cells If....

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I need to modify this code but I am a bit lost because I want to delete Cells (Z:AA) if the Value in Column AA = "NEW"

I have values down column Z starting in Z1. I have a formula in Column AA that tells me if the value in Z is something new or not. I want to reduce the list in column Z down to only new items, then take that reduced list and paste it to the bottom of column A

This is the code I have that deletes Row, but I am trying to modify it for the above

Code:
Dim LR As Long, i As Long, X As Variant
X = Sheets("Sheet1").Range("A1").Value
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If Range("P" & i).Value <> X Then Rows(i).Delete
Next I

Thanks!!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
this will copy the cells Z:AA to Col A

Code:
With ActiveSheet
    .AutoFilterMode = False
        .Range("Z1:AA" & .Range("AA" & Rows.Count).End(xlUp).Row).AutoFilter Field:=2, Criteria1:="new"
        .Range("Z1:AA" & .Range("AA" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy Destination:=.Range("A" & .Range("A" & Rows.Count).End(xlUp).Row + 1)
    .AutoFilterMode = False
End With
 
Last edited:
Upvote 0
Thank you so much. But its copying the very first set of cells (Z1:AA1) even if it doesn't say "New"

Also, I didn't need to copy column AA.

I really appreciate your help
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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