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

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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
 
Upvote 0
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
 
Upvote 0
Alex I resolved the issue
Changed
Code:
 For r = LastRow To 1 Step -1

to

For r = LR To 1 Step -1
 
Upvote 0

Forum statistics

Threads
1,214,428
Messages
6,119,420
Members
448,895
Latest member
omarahmed1

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