deleting rows based on value of cells in column

Keyss

New Member
Joined
Jul 15, 2018
Messages
13
So hi,

First off, thank you to NoSparks who helped me previously, was a great help & deserves a 'callout.'

Issue I need help with.

I'm trying to delete rows from a table based on a value contained of cells in a particular column. I can do it manually however using the recorded macro, it deletes 'all' information in the spreadsheet.

I'm highlighting a column that has the specific value 'Yes' in it that i want to delete the rows of. I CRTL F, do 'find all' on value 'Yes', then CRTL A to highlight all these cells. Next step is closing the FIND / FIND REPLACE box and CRTL -, choose Entire Row in the Delete box and click the OK button. This is when it deletes ALL data in the spreadsheet instead of just the rows of the highlighted cells.

Code below

Sub Macro4()
'
' Macro4 Macro
'


'
Windows("usage for Macro 4 code example.xls").Activate
Columns("G:G").Select
Selection.EntireRow.Delete
Windows("! Contract review Macro APP.xlsm").Activate
End Sub


As you can see it records nothing of the specific "Yes" value in which to delete the rows containing and I don't know enough yet to work it out.

Thank you for any assistance.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
try use this once you have all your yes cells selected

Code:
Sub deleterowstest1()

Selection.EntireRow.Delete

End Sub
 
Upvote 0
So are you saying if Yes is in column G you want that entire row deleted

So if Row(3) column G has Yes then you want Row(3) deleted is this what you want.

And if Yes in in Row(5) column G you want Row(5) deleted.
 
Upvote 0
Maybe something like this...
It will delete all rows that have a "Yes" in Column "G"....you don't need to select them, just run the code on the active sheet

Code:
Sub MM()
With Columns("G")
    .AutoFilter Field:=1, Criteria1:="Yes"
    .Resize(Rows.Count - 1).Offset(1).EntireRow.Delete
    .AutoFilter
End With
End Sub
 
Upvote 0
Perhaps.....

Code:
Sub DeleteRws()

Application.ScreenUpdating = False

With ActiveSheet.[A1].CurrentRegion
                .AutoFilter 7, "Yes"
                .Offset(1).EntireRow.Delete
                .AutoFilter
End With
                
Application.ScreenUpdating = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
fhqwgads - this deleted the entire data on the sheet

My Aswer Is This - answer, yes that is exactly what i am trying to achieve

Michael M - came up with running error
><div style=font-size:9px;font-family:Arial, Helvetica, sans-serif;width:127px;font-color:

vberror
Run-Time error '1004': The command could not be completed by using the range specified. Select a single cell within the range and try the command again.
In debug the following is highlighted - .Autofilter Field:=1, Criterial:="Yes"
 
Upvote 0
do you have a header row on the sheet ??
 
Upvote 0
vcoolio,

Thank you so much, it worked. I'm very excited!! :)

And thank you to everyone that offered assistance.

I can't wait until I know enough to be able to help somebody else.

Thanks all
 
Upvote 0
You're welcome Keyss.

Glad we could help.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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