Deleting row in another sheet depending on the value of a cell in the first sheet

Martha Mary

New Member
Joined
May 5, 2022
Messages
17
Office Version
  1. 2010
Platform
  1. Windows
Hi
I have some VBA code which works fine to delete all rows in Sheet2 if the corresponding ID exists in Sheet1:

Sub CheckA()
Dim LR As Long, i As Long
With Sheets("Sheet1")
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
If IsError(Application.Match(.Range("A" & i).Value, Sheets("Sheet2").Columns("A"), 0)) Then Rows(i).Delete
Next i
End With
End Sub

However I only want to delete the corresponding rows in Sheet2 if the contents of column M in Sheet1= "No" - can anyone advise how I need to amend this code to do this?

Appreciate any advice!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
That's fine as long as it still shows the problem.
You will need to upload it to a share site such as OneDrive, GoogleDrive, DropBox. Then mark for sharing & post the link you are given here.
 
Upvote 0
That's fine as long as it still shows the problem.
You will need to upload it to a share site such as OneDrive, GoogleDrive, DropBox. Then mark for sharing & post the link you are given here.
Sorry I dont think we have permissions to use those functions
 
Upvote 0
Ok.
Did you copy/paste the code I supplied, or retype it?
 
Upvote 0
i pasted it
I was going to try to do this via Google Drive on my phone as it is only dummy data, but I dont have the correct version of Excel to support the macros.......but a thousand thanks for trying to help!
 
Upvote 0
Not sure what your saying, all versions of Excel support macros (except the browser version)
 
Upvote 0
Not sure what your saying, all versions of Excel support macros (except the browser version)
No what I mean is my the version isnt supported on my phone. I set up a formula there just to double check for training spaces and there are none. Not sure why the macro isnt working - but thank you anyway
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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