PC Review


Reply
Thread Tools Rate Thread

Delete rows where colums 4 is empty

 
 
Robert
Guest
Posts: n/a
 
      9th Jul 2007
Hi All,

Could someone perhaps advice which VBA statement to use for: delete
all rows within a certain sheet where column 4 is empty

Many thanks in advance!

Regards,
Robert

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      9th Jul 2007
The trick with this problem is you need two counter. One to keep track of
the number of times to loop. the 2nd count is to keep track of the row number


LastRow = cells(Rows.Count,4).end(xlup).Row
loopCount = 1
rowcount = 1
do while loopcount <= Lastrow

if isempty(cells(rowcount,4)) then

cells(rowcount,4).entirerow.delete
else
RowCount = rowcount + 1
end if

loopcount = loopcount + 1
loop

"Robert" wrote:

> Hi All,
>
> Could someone perhaps advice which VBA statement to use for: delete
> all rows within a certain sheet where column 4 is empty
>
> Many thanks in advance!
>
> Regards,
> Robert
>
>

 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      9th Jul 2007
Another way

Dim myDeleteRange As Range
Dim r As Range
Dim lRow As Long

Set aWS = ActiveSheet

Set myRange = aWS.Cells(aWS.Rows.Count, 1).Resize(1, aWS.Columns.Count)
Debug.Print myRange.Address
lRow = myRange.End(xlUp).Row
Debug.Print lRow

Set myRange = aWS.Cells(1, 4).Resize(lRow, 1)
Debug.Print myRange.Address

Set myDeleteRange = Nothing

For Each r In myRange
If IsEmpty(r) Then
If myDeleteRange Is Nothing Then
Set myDeleteRange = r
Else
Set myDeleteRange = Union(myDeleteRange, r)
End If
End If
Next r

"Robert" wrote:

> Hi All,
>
> Could someone perhaps advice which VBA statement to use for: delete
> all rows within a certain sheet where column 4 is empty
>
> Many thanks in advance!
>
> Regards,
> Robert
>
>

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      9th Jul 2007
Barb nice code, but you forgot to do the actual delete.
You should add
myDeleteRange.entirerow.delete


"Barb Reinhardt" wrote:

> Another way
>
> Dim myDeleteRange As Range
> Dim r As Range
> Dim lRow As Long
>
> Set aWS = ActiveSheet
>
> Set myRange = aWS.Cells(aWS.Rows.Count, 1).Resize(1, aWS.Columns.Count)
> Debug.Print myRange.Address
> lRow = myRange.End(xlUp).Row
> Debug.Print lRow
>
> Set myRange = aWS.Cells(1, 4).Resize(lRow, 1)
> Debug.Print myRange.Address
>
> Set myDeleteRange = Nothing
>
> For Each r In myRange
> If IsEmpty(r) Then
> If myDeleteRange Is Nothing Then
> Set myDeleteRange = r
> Else
> Set myDeleteRange = Union(myDeleteRange, r)
> End If
> End If
> Next r
>
> "Robert" wrote:
>
> > Hi All,
> >
> > Could someone perhaps advice which VBA statement to use for: delete
> > all rows within a certain sheet where column 4 is empty
> >
> > Many thanks in advance!
> >
> > Regards,
> > Robert
> >
> >

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      9th Jul 2007
if they are really empty

Sub Deleterows()
dim r as Range
On Error Resume Next
Worksheets("Sheet1").Columns(4).specialCells(xlBlanks).Entirerow.delete
On goto 0
end Sub

If you have more than 8192 separate areas (not just cells) in column 4 that
are blank, this will not work, but that is rarely the case.

--
Regards,
Tom Ogilvy


"Robert" wrote:

> Hi All,
>
> Could someone perhaps advice which VBA statement to use for: delete
> all rows within a certain sheet where column 4 is empty
>
> Many thanks in advance!
>
> Regards,
> Robert
>
>

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      9th Jul 2007
If there are more than 8192 ares, can you run the code twice or more to
eliminate all the row?

"Tom Ogilvy" wrote:

> if they are really empty
>
> Sub Deleterows()
> dim r as Range
> On Error Resume Next
> Worksheets("Sheet1").Columns(4).specialCells(xlBlanks).Entirerow.delete
> On goto 0
> end Sub
>
> If you have more than 8192 separate areas (not just cells) in column 4 that
> are blank, this will not work, but that is rarely the case.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Robert" wrote:
>
> > Hi All,
> >
> > Could someone perhaps advice which VBA statement to use for: delete
> > all rows within a certain sheet where column 4 is empty
> >
> > Many thanks in advance!
> >
> > Regards,
> > Robert
> >
> >

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      9th Jul 2007
You would need to build the code to work in increments that would result in
less than 8192 rows.

Ron de Bruin has documents some approaches:

http://www.rondebruin.nl/specialcells.htm

--
Regards,
Tom Ogilvy


"Joel" wrote:

> If there are more than 8192 ares, can you run the code twice or more to
> eliminate all the row?
>
> "Tom Ogilvy" wrote:
>
> > if they are really empty
> >
> > Sub Deleterows()
> > dim r as Range
> > On Error Resume Next
> > Worksheets("Sheet1").Columns(4).specialCells(xlBlanks).Entirerow.delete
> > On goto 0
> > end Sub
> >
> > If you have more than 8192 separate areas (not just cells) in column 4 that
> > are blank, this will not work, but that is rarely the case.
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> >
> > "Robert" wrote:
> >
> > > Hi All,
> > >
> > > Could someone perhaps advice which VBA statement to use for: delete
> > > all rows within a certain sheet where column 4 is empty
> > >
> > > Many thanks in advance!
> > >
> > > Regards,
> > > Robert
> > >
> > >

 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      10th Jul 2007
DOH! You're right. Thanks for the correction.

"Joel" wrote:

> Barb nice code, but you forgot to do the actual delete.
> You should add
> myDeleteRange.entirerow.delete
>
>
> "Barb Reinhardt" wrote:
>
> > Another way
> >
> > Dim myDeleteRange As Range
> > Dim r As Range
> > Dim lRow As Long
> >
> > Set aWS = ActiveSheet
> >
> > Set myRange = aWS.Cells(aWS.Rows.Count, 1).Resize(1, aWS.Columns.Count)
> > Debug.Print myRange.Address
> > lRow = myRange.End(xlUp).Row
> > Debug.Print lRow
> >
> > Set myRange = aWS.Cells(1, 4).Resize(lRow, 1)
> > Debug.Print myRange.Address
> >
> > Set myDeleteRange = Nothing
> >
> > For Each r In myRange
> > If IsEmpty(r) Then
> > If myDeleteRange Is Nothing Then
> > Set myDeleteRange = r
> > Else
> > Set myDeleteRange = Union(myDeleteRange, r)
> > End If
> > End If
> > Next r
> >
> > "Robert" wrote:
> >
> > > Hi All,
> > >
> > > Could someone perhaps advice which VBA statement to use for: delete
> > > all rows within a certain sheet where column 4 is empty
> > >
> > > Many thanks in advance!
> > >
> > > Regards,
> > > Robert
> > >
> > >

 
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
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Delete rows where colums match Del_F Microsoft Excel Programming 3 16th Aug 2007 10:04 AM
delete blank rows & colums =?Utf-8?B?UWF6aSBBaG1hZA==?= Microsoft Excel Misc 3 26th Dec 2006 05:32 AM
Delete Rows with Empty Cells with empty column 1 Scott Microsoft Excel Programming 6 2nd Oct 2006 11:57 PM
Delete all nonused rows and colums Marcus Pedersén Microsoft Excel Discussion 2 1st Aug 2004 08:58 PM


Features
 

Advertising
 

Newsgroups
 


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