Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Delete rows where colums 4 is empty

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Delete rows where colums 4 is empty

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Delete rows where colums 4 is empty

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Delete rows where colums 4 is empty

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Delete rows where colums 4 is empty

if they are really empty

Sub Deleterows()
dim r as Range
On Error Resume Next
Worksheets("Sheet1").Columns(4).specialCells(xlBla nks).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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Delete rows where colums 4 is empty

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(xlBla nks).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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Delete rows where colums 4 is empty

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(xlBla nks).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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Delete rows where colums 4 is empty

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hpw do I delete multiple empty rows found between filled rows? Bill Excel Worksheet Functions 2 November 15th 09 07:12 PM
How to Delete empty rows in excel in b/w rows with values Dennis Excel Worksheet Functions 3 August 28th 07 04:15 PM
delete blank rows & colums Qazi Ahmad Excel Discussion (Misc queries) 3 December 26th 06 05:32 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
Delete Rows with Empty Cells with empty column 1 Scott Excel Programming 5 October 2nd 06 11:57 PM


All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"