Macro to delete rows where row contains ' (row looks blank but contains ')

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,776
Office Version
  1. 2019
Platform
  1. Windows
I would like to delete all rows in sheets 1 & 2 where the rows in Col A contain a ' (row actually looks blank but contain the ')

I have tried to write code just for the active sheet but cannot get it to work

It would be appreciated if someone could kindly assist me to amend my code as well as to incorporate sheets 1 & 2

Code:
 Sub Delete_Rows_apostrophe()
Dim r As Long
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For r = LastRow To 1 Step -1
If Cells(r, 1) = "'" Then
Rows(r).Delete
End If
Next r
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Alex Blakenburg

Well-known Member
Joined
Feb 23, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
Unless you have a requirement to distinguish between an empty string "" and a single quote '
This should work.
It will ignore empty/blank (null) rows.

VBA Code:
If Cells(r, 1) = "" And Not IsEmpty(Cells(r, 1)) Then
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,776
Office Version
  1. 2019
Platform
  1. Windows
Thanks Alex. Code works perfectly
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,776
Office Version
  1. 2019
Platform
  1. Windows
Hi Alex

I tried to amend the code to delete this on all sheets, but it is not doing so

Kindly check & amend


Code:
 Sub Delete_Rows_apostrophe()
Dim I As Long
Dim r As Long
Dim LR As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LastRow To 1 Step -1
For I = 1 To Worksheets.Count
 With Worksheets(I)

If .Cells(r, 1) = "" And Not IsEmpty(.Cells(r, 1)) Then

.Rows(r).Delete
End If
 End With
  Next I
Next r

 
  
End Sub
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,776
Office Version
  1. 2019
Platform
  1. Windows
Alex I resolved the issue
Changed
Code:
 For r = LastRow To 1 Step -1

to

For r = LR To 1 Step -1
 

Watch MrExcel Video

Forum statistics

Threads
1,129,361
Messages
5,635,812
Members
416,884
Latest member
leeshjay

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
Top