ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to delete rows if they don't begin with "0" (https://www.excelbanter.com/excel-programming/406615-macro-delete-rows-if-they-dont-begin-0-a.html)

No Name

Macro to delete rows if they don't begin with "0"
 
Hi - and thanks for reading this.
I have a macro where I am trying to delete rows that don't begin with "0".
These are text cells (hence the apostrophes). The sample below deletes the
rows if they DO begin with "0" and I can't find out how to make it delete if
they DON'T being with "0". I've searched the group for ages - without
success. I've tried Not Like - but that doesn't work.
Thanks for your help (it's probably easy for you!)

Application.ScreenUpdating = False
For i = 90 To 3 Step -1
If Cells(i, 1).Value Like "0*" Then Rows(i).Delete
Next
Application.ScreenUpdating = True



[email protected]

Macro to delete rows if they don't begin with "0"
 
Hi
You could try

If left(Cells(i, 1).Value,1) ="0" Then Rows(i).Delete

regards
Paul


On Feb 25, 12:33*pm, <Andy wrote:
Hi - and thanks for reading this.
I have a macro where I am trying to delete rows that don't begin with "0".
These are text cells (hence the apostrophes). The sample below deletes the
rows if they DO begin with "0" and I can't find out how to make it delete if
they DON'T being with "0". I've searched the group for ages - without
success. I've tried Not Like - but that doesn't work.
Thanks for your help (it's probably easy for you!)

Application.ScreenUpdating = False
* For i = 90 To 3 Step -1
* * If Cells(i, 1).Value Like "0*" Then Rows(i).Delete
* Next
Application.ScreenUpdating = True



Mike H

Macro to delete rows if they don't begin with "0"
 
Andy,

Try this

If Left(Cells(i, 1).Value, 1) = "o" Then Rows(i).Delete

Note this is case sensitive for a non case sensitive version use
If UCase(Left(Cells(i, 1).Value, 1)) = "O" Then Rows(i).Delete

Mike

"Andy" wrote:

Hi - and thanks for reading this.
I have a macro where I am trying to delete rows that don't begin with "0".
These are text cells (hence the apostrophes). The sample below deletes the
rows if they DO begin with "0" and I can't find out how to make it delete if
they DON'T being with "0". I've searched the group for ages - without
success. I've tried Not Like - but that doesn't work.
Thanks for your help (it's probably easy for you!)

Application.ScreenUpdating = False
For i = 90 To 3 Step -1
If Cells(i, 1).Value Like "0*" Then Rows(i).Delete
Next
Application.ScreenUpdating = True




No Name

Macro to delete rows if they don't begin with "0"
 
Hi - and thanks!

I've modified it to < "0" and that's great!

Cheers.

wrote in message
...
Hi
You could try

If left(Cells(i, 1).Value,1) ="0" Then Rows(i).Delete

regards
Paul


On Feb 25, 12:33 pm, <Andy wrote:
Hi - and thanks for reading this.
I have a macro where I am trying to delete rows that don't begin with "0".
These are text cells (hence the apostrophes). The sample below deletes the
rows if they DO begin with "0" and I can't find out how to make it delete
if
they DON'T being with "0". I've searched the group for ages - without
success. I've tried Not Like - but that doesn't work.
Thanks for your help (it's probably easy for you!)

Application.ScreenUpdating = False
For i = 90 To 3 Step -1
If Cells(i, 1).Value Like "0*" Then Rows(i).Delete
Next
Application.ScreenUpdating = True




mo_in_france[_2_]

Macro to delete rows if they don't begin with "0"
 
On 25 Feb, 13:33, <Andy wrote:
Hi - and thanks for reading this.
I have a macro where I am trying to delete rows that don't begin with "0".
These are text cells (hence the apostrophes). The sample below deletes the
rows if they DO begin with "0" and I can't find out how to make it delete if
they DON'T being with "0". I've searched the group for ages - without
success. I've tried Not Like - but that doesn't work.
Thanks for your help (it's probably easy for you!)

Application.ScreenUpdating = False
* For i = 90 To 3 Step -1
* * If Cells(i, 1).Value Like "0*" Then Rows(i).Delete
* Next
Application.ScreenUpdating = True


Do you really need a macro?

If you don't, then....

1) filter on the data such that the rows you don't want are visible
2) Select the visible rows
3) Delete the rows


Regards


All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com