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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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.
Hey there i have been able to save this to One Drive - what link do I need to copy this to? I havent used this before
 
Upvote 0
If you right click the file & select Share, a new window will open & click the Copy button, then another window will open click copy on that & then paste the link to the thread.
 
Upvote 0
I get an error with that, it says the fileformat doesn't match the extension.
The file should really be either an xlsm or xlsb file
 
Upvote 0
I get an error with that, it says the fileformat doesn't match the extension.
The file should really be either an xlsm or xlsb file
It is an xlsm file but i am getting a message on my One Drive to say this version of Excel cant run VBA macros so that must be where the problem is
 
Upvote 0
You should still be able to copy macro enabled files to onedrive.
 
Upvote 0
You should still be able to copy macro enabled files to onedrive.
i have it copied ok and i can see it but it doesnt send - I can send as an attachment but not as a link. So sorry to have wasted your time
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

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