A little more Macro Magic required?

mikemcbain

Board Regular
Joined
Nov 14, 2005
Messages
152
Office Version
  1. 365
Platform
  1. Windows
G'day Macro Magicians

I would like to add some code to a macro that I use daily.

I would like it to select Column C which predominantly contains two digit numbers however some Rows contain the Text "No."

I would like the macro code to remove all those Rows containing No. EXCEPT in Row 1.

Waiting with great anticipation.

Old MIke.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hey Mike
How about
VBA Code:
Sub MM1()
  With Range("C2", Cells(Rows.Count, "C").End(xlUp))
    .Replace "No", "#N/A", xlWhole, , False, , False, False
    Columns("C").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
End Sub
 
Upvote 0
Hey Mike
How about
VBA Code:
Sub MM1()
  With Range("C2", Cells(Rows.Count, "C").End(xlUp))
    .Replace "No", "#N/A", xlWhole, , False, , False, False
    Columns("C").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
End Sub
Michael - you must be ageing? :biggrin:
Worked like a charm after I put the little dot in "No."
Thank you once again.
Old Mike.
 
Upvote 0
Aahh yes....sorry I thought the period was not included....glad it worked for you.. (y) (y)
 
Upvote 0
FWIW, assuming those numbers are in fact numbers and not text values, there is no need to do the replacement suggested to allow use of the SpecialCells feature.
(I have also assumed the "No." values are the only text values in the column, are not the result of formulas & that at least one "No." exists below row 1.)

If the above is correct then you could also try this one-liner
VBA Code:
Sub RemoveRows()
  Range("C2", Range("C" & Rows.Count).End(xlUp)).SpecialCells(xlConstants, xlTextValues).EntireRow.Delete
End Sub
 
Upvote 0
Solution
Since SpecialCells only operates on the UsedRange, you could also use this macro (same assumptions as Peter posted)...
VBA Code:
Sub RemoveRows()
  Range("C2:C" & Rows.Count).SpecialCells(xlConstants, xlTextValues).EntireRow.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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