Delete row starting with an asterix

fddekker

Board Regular
Joined
Jun 30, 2008
Messages
86
Office Version
  1. 365
Platform
  1. Windows
I am trying to write a macro that would delete a row if the first character in column A is an asterisk. None of my attempts work.
(using the left function in VBA and searching for ~*)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
When I search for an asterisk and replace it with any other string and then search for the string, I am able to do it.
(Again, replacing ~*)
<o:p></o:p>
Currently I am using this macro, but would like to make the code more efficient by directly deleting rows that start with the asterisk.
<o:p></o:p>
Any advice??
<o:p></o:p>
Sub DeleteProjectLevel()
Dim LR As Long

'Replace * with a Z
Columns("A:A").Select
Selection.Replace What:="~*", Replacement:="Z", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Insert Shift:=xlToRight
Range("A1").Select

'Create check colum in A
ActiveCell.FormulaR1C1 = "=IF(LEFT(RC[1],1)=""Z"",""<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:stockticker>TRUE</st1:stockticker>"",""FALSE"")"
LR = Range("B" & Rows.Count).End(xlUp).Row
Range("A1:A" & LR).Formula = Range("A1").Formula
Application.CutCopyMode = False
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Replace What:="<st1:stockticker>TRUE</st1:stockticker>", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.SpecialCells(xlCellTypeBlanks).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete

'Delete check column
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
<o:p></o:p>
End Sub

<o:p></o:p>
<o:p></o:p>

<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
May be this? Assumes row 1 is a heading row.

VBA Code:
Sub DeleteRows()
  Application.ScreenUpdating = False
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    .AutoFilter Field:=1, Criteria1:="=~**"
    .Offset(1).EntireRow.Delete
    .AutoFilter
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Wow, you guys ARE on the ball. Never knew that trick.

Works perfect! Thanks.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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