PC Review


Reply
Thread Tools Rate Thread

Delete rows with macro not working

 
 
Greg Snidow
Guest
Posts: n/a
 
      3rd Oct 2008
Greetings all. I have a macro that, among other things, deletes all rows
from a sheet where ever a cell in one column is blank. The part of the macro
in question is below.

' Delete rows with no job number
Dim rng As Range
On Error Resume Next
Set rng = Columns(4).SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If

The problem is that recently it does not work for some rows on a report from
a particular user. The cells in column 4 appear to be blank, but when I run
the macro, they are not deleted. If I first highlight all the cells that
appear to be blank, and hit delete, then run the macro, it works fine, so
there seems to be some zero length strings, or just blank spaces in some of
the cells. My question is, how can I include these cells in the set to be
deleted? Thank you.

Greg Snidow

 
Reply With Quote
 
 
 
 
Thomas [PBD]
Guest
Posts: n/a
 
      3rd Oct 2008
Greg,

Have you used the =ISBLANK(<cell>) function to determine if the cells are in
fact empty? If so, and it returns "FALSE" then you have some underlying code.

You would have to figure out what exactly are in the cells, are they spaces,
are they Hardcode returns (which appear as null spots but are infact coding
into the cells), or a special character of some type. There are a lot of
errors sometimes when users attempt to import excel information from the
Internet primarily the Hardcode returns.
I believe without the actual items in the cells, you might have a hard time
accomplishing this task. Maybe you can watch the user enter the information
one day and figure out where he is going astray.

--
--Thomas [PBD]
Working hard to make working easy.


"Greg Snidow" wrote:

> Greetings all. I have a macro that, among other things, deletes all rows
> from a sheet where ever a cell in one column is blank. The part of the macro
> in question is below.
>
> ' Delete rows with no job number
> Dim rng As Range
> On Error Resume Next
> Set rng = Columns(4).SpecialCells(xlBlanks)
> On Error GoTo 0
> If Not rng Is Nothing Then
> rng.EntireRow.Delete
> End If
>
> The problem is that recently it does not work for some rows on a report from
> a particular user. The cells in column 4 appear to be blank, but when I run
> the macro, they are not deleted. If I first highlight all the cells that
> appear to be blank, and hit delete, then run the macro, it works fine, so
> there seems to be some zero length strings, or just blank spaces in some of
> the cells. My question is, how can I include these cells in the set to be
> deleted? Thank you.
>
> Greg Snidow
>

 
Reply With Quote
 
Greg Snidow
Guest
Posts: n/a
 
      3rd Oct 2008
Thomas,
Thanks for the quick reply. Indeed, the ISBLANK function returns FALSE for
the rows in question. The report is all manual entry, no web coding
anywhere. The users simply copy yesterdays sheet into a new sheet, delete
all the data, then type in new data for today. The user of the one that is
broken is in another state, so I can not really see what she is doing. The
cell in question contains a job number that is *always* between 7 and 11
characters long. Could I somehow alter the macro to delete all rows where
the LEN of that cell < 7? The LEN() function returns a value of 1 for all the
seemingly blank cells, so they appear to be just spaces. Is there a way to
determine what they are?

"Thomas [PBD]" wrote:

> Greg,
>
> Have you used the =ISBLANK(<cell>) function to determine if the cells are in
> fact empty? If so, and it returns "FALSE" then you have some underlying code.
>
> You would have to figure out what exactly are in the cells, are they spaces,
> are they Hardcode returns (which appear as null spots but are infact coding
> into the cells), or a special character of some type. There are a lot of
> errors sometimes when users attempt to import excel information from the
> Internet primarily the Hardcode returns.
> I believe without the actual items in the cells, you might have a hard time
> accomplishing this task. Maybe you can watch the user enter the information
> one day and figure out where he is going astray.
>
> --
> --Thomas [PBD]
> Working hard to make working easy.
>
>
> "Greg Snidow" wrote:
>
> > Greetings all. I have a macro that, among other things, deletes all rows
> > from a sheet where ever a cell in one column is blank. The part of the macro
> > in question is below.
> >
> > ' Delete rows with no job number
> > Dim rng As Range
> > On Error Resume Next
> > Set rng = Columns(4).SpecialCells(xlBlanks)
> > On Error GoTo 0
> > If Not rng Is Nothing Then
> > rng.EntireRow.Delete
> > End If
> >
> > The problem is that recently it does not work for some rows on a report from
> > a particular user. The cells in column 4 appear to be blank, but when I run
> > the macro, they are not deleted. If I first highlight all the cells that
> > appear to be blank, and hit delete, then run the macro, it works fine, so
> > there seems to be some zero length strings, or just blank spaces in some of
> > the cells. My question is, how can I include these cells in the set to be
> > deleted? Thank you.
> >
> > Greg Snidow
> >

 
Reply With Quote
 
Thomas [PBD]
Guest
Posts: n/a
 
      3rd Oct 2008
Greg,

You could do a either of those. You can amend your macro to exclude
anything either greater than 11 and/or less than 7, considering that you
trust the data. Secondly, you could use =CODE(<cell>) function to determine
the entry in the cell. 32 is a space, 13 is a carriage return, and 10 is a
hardcode return (ALT+Enter in the cell). In the VBA, the Asc() function will
determine the number. You could Dim the string of the cell in question and
use the Asc(<rng>) to exclude it with an If statement.

--
--Thomas [PBD]
Working hard to make working easy.
Answered your question? Click ''Yes'' below.


"Greg Snidow" wrote:

> Thomas,
> Thanks for the quick reply. Indeed, the ISBLANK function returns FALSE for
> the rows in question. The report is all manual entry, no web coding
> anywhere. The users simply copy yesterdays sheet into a new sheet, delete
> all the data, then type in new data for today. The user of the one that is
> broken is in another state, so I can not really see what she is doing. The
> cell in question contains a job number that is *always* between 7 and 11
> characters long. Could I somehow alter the macro to delete all rows where
> the LEN of that cell < 7? The LEN() function returns a value of 1 for all the
> seemingly blank cells, so they appear to be just spaces. Is there a way to
> determine what they are?
>
> "Thomas [PBD]" wrote:
>
> > Greg,
> >
> > Have you used the =ISBLANK(<cell>) function to determine if the cells are in
> > fact empty? If so, and it returns "FALSE" then you have some underlying code.
> >
> > You would have to figure out what exactly are in the cells, are they spaces,
> > are they Hardcode returns (which appear as null spots but are infact coding
> > into the cells), or a special character of some type. There are a lot of
> > errors sometimes when users attempt to import excel information from the
> > Internet primarily the Hardcode returns.
> > I believe without the actual items in the cells, you might have a hard time
> > accomplishing this task. Maybe you can watch the user enter the information
> > one day and figure out where he is going astray.
> >
> > --
> > --Thomas [PBD]
> > Working hard to make working easy.
> >
> >
> > "Greg Snidow" wrote:
> >
> > > Greetings all. I have a macro that, among other things, deletes all rows
> > > from a sheet where ever a cell in one column is blank. The part of the macro
> > > in question is below.
> > >
> > > ' Delete rows with no job number
> > > Dim rng As Range
> > > On Error Resume Next
> > > Set rng = Columns(4).SpecialCells(xlBlanks)
> > > On Error GoTo 0
> > > If Not rng Is Nothing Then
> > > rng.EntireRow.Delete
> > > End If
> > >
> > > The problem is that recently it does not work for some rows on a report from
> > > a particular user. The cells in column 4 appear to be blank, but when I run
> > > the macro, they are not deleted. If I first highlight all the cells that
> > > appear to be blank, and hit delete, then run the macro, it works fine, so
> > > there seems to be some zero length strings, or just blank spaces in some of
> > > the cells. My question is, how can I include these cells in the set to be
> > > deleted? Thank you.
> > >
> > > Greg Snidow
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete 2 rows every 500 rows beginner1.mat@hotmail.com Microsoft Excel Programming 3 3rd Feb 2008 01:52 PM
Trying to delete rows and it's not working tahrah Microsoft Excel Programming 4 13th Jan 2007 01:00 PM
Macro to delete all rows except rows that start $$11$ 11 Crowbar via OfficeKB.com Microsoft Excel Programming 7 23rd Oct 2005 04:30 PM
Macro to select 4 entire rows and then delete rows Scott Viney Microsoft Excel Discussion 3 22nd Sep 2005 07:02 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Microsoft Excel Programming 4 3rd May 2004 08:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:12 PM.