PC Review


Reply
Thread Tools Rate Thread

Delete Rows with Empty Cells with empty column 1

 
 
Scott
Guest
Posts: n/a
 
      30th Sep 2006
My below sub below corectly deletes any rows that have empty cells within a
hard-coded range of A1:A150. What I'd like to do is to search the entire
range of cells containing values and delete any rows that have empty column
1 cells.

It would achieve the same reults as my current code, but I could get rid of
my hard coded reference. I never will know how many rows my spreadsheet will
be and would like to avoid hard-code reference.

Can someone help me re-write my code to achieve this?


CODE **********************

Sub DeleteRowsWithEmptyColumn1()
' deletes rows with empty cells in column 1
Dim rng As Range
On Error Resume Next
Set rng = ActiveSheet.Range("A1:A150").SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub


 
Reply With Quote
 
 
 
 
Gord Dibben
Guest
Posts: n/a
 
      30th Sep 2006
Sub DeleteRowsWithEmptyColumn1()
' deletes rows with empty cells in column 1
Dim rng As Range
On Error Resume Next
Set rng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) _
.SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub


Gord Dibben MS Excel MVP

On Fri, 29 Sep 2006 19:39:09 -0500, "Scott" <(E-Mail Removed)> wrote:

>My below sub below corectly deletes any rows that have empty cells within a
>hard-coded range of A1:A150. What I'd like to do is to search the entire
>range of cells containing values and delete any rows that have empty column
>1 cells.
>
>It would achieve the same reults as my current code, but I could get rid of
>my hard coded reference. I never will know how many rows my spreadsheet will
>be and would like to avoid hard-code reference.
>
>Can someone help me re-write my code to achieve this?
>
>
>CODE **********************
>
>Sub DeleteRowsWithEmptyColumn1()
> ' deletes rows with empty cells in column 1
> Dim rng As Range
> On Error Resume Next
> Set rng = ActiveSheet.Range("A1:A150").SpecialCells(xlBlanks)
> On Error GoTo 0
> If Not rng Is Nothing Then
> rng.EntireRow.Delete
> End If
>End Sub
>


 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      30th Sep 2006
I get an error "Cannot use that command on overlapping selections". It
doesn't like " rng.EntireRow.Delete"


"Gord Dibben" <gorddibbATshawDOTca> wrote in message
news:(E-Mail Removed)...
> Sub DeleteRowsWithEmptyColumn1()
> ' deletes rows with empty cells in column 1
> Dim rng As Range
> On Error Resume Next
> Set rng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) _
> .SpecialCells(xlBlanks)
> On Error GoTo 0
> If Not rng Is Nothing Then
> rng.EntireRow.Delete
> End If
> End Sub
>
>
> Gord Dibben MS Excel MVP
>
> On Fri, 29 Sep 2006 19:39:09 -0500, "Scott" <(E-Mail Removed)>
> wrote:
>
>>My below sub below corectly deletes any rows that have empty cells within
>>a
>>hard-coded range of A1:A150. What I'd like to do is to search the entire
>>range of cells containing values and delete any rows that have empty
>>column
>>1 cells.
>>
>>It would achieve the same reults as my current code, but I could get rid
>>of
>>my hard coded reference. I never will know how many rows my spreadsheet
>>will
>>be and would like to avoid hard-code reference.
>>
>>Can someone help me re-write my code to achieve this?
>>
>>
>>CODE **********************
>>
>>Sub DeleteRowsWithEmptyColumn1()
>> ' deletes rows with empty cells in column 1
>> Dim rng As Range
>> On Error Resume Next
>> Set rng = ActiveSheet.Range("A1:A150").SpecialCells(xlBlanks)
>> On Error GoTo 0
>> If Not rng Is Nothing Then
>> rng.EntireRow.Delete
>> End If
>>End Sub
>>

>



 
Reply With Quote
 
Mike Fogleman
Guest
Posts: n/a
 
      30th Sep 2006
You need to find the last row as a variable:

Sub DeleteRowsWithEmptyColumn1()
' deletes rows with empty cells in column 1
Dim rng As Range
Dim LRow As Long

On Error Resume Next
LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = ActiveSheet.Range("A1:A" & LRow).SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub

Mike F
"Scott" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I get an error "Cannot use that command on overlapping selections". It
>doesn't like " rng.EntireRow.Delete"
>
>
> "Gord Dibben" <gorddibbATshawDOTca> wrote in message
> news:(E-Mail Removed)...
>> Sub DeleteRowsWithEmptyColumn1()
>> ' deletes rows with empty cells in column 1
>> Dim rng As Range
>> On Error Resume Next
>> Set rng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) _
>> .SpecialCells(xlBlanks)
>> On Error GoTo 0
>> If Not rng Is Nothing Then
>> rng.EntireRow.Delete
>> End If
>> End Sub
>>
>>
>> Gord Dibben MS Excel MVP
>>
>> On Fri, 29 Sep 2006 19:39:09 -0500, "Scott" <(E-Mail Removed)>
>> wrote:
>>
>>>My below sub below corectly deletes any rows that have empty cells within
>>>a
>>>hard-coded range of A1:A150. What I'd like to do is to search the entire
>>>range of cells containing values and delete any rows that have empty
>>>column
>>>1 cells.
>>>
>>>It would achieve the same reults as my current code, but I could get rid
>>>of
>>>my hard coded reference. I never will know how many rows my spreadsheet
>>>will
>>>be and would like to avoid hard-code reference.
>>>
>>>Can someone help me re-write my code to achieve this?
>>>
>>>
>>>CODE **********************
>>>
>>>Sub DeleteRowsWithEmptyColumn1()
>>> ' deletes rows with empty cells in column 1
>>> Dim rng As Range
>>> On Error Resume Next
>>> Set rng = ActiveSheet.Range("A1:A150").SpecialCells(xlBlanks)
>>> On Error GoTo 0
>>> If Not rng Is Nothing Then
>>> rng.EntireRow.Delete
>>> End If
>>>End Sub
>>>

>>

>
>



 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      2nd Oct 2006
for some reason, the code still isn't deleting my row with empty cell in
column 1. Can you check it again?

"Mike Fogleman" <(E-Mail Removed)> wrote in message
news:3OCdnU9t4psH-(E-Mail Removed)...
> You need to find the last row as a variable:
>
> Sub DeleteRowsWithEmptyColumn1()
> ' deletes rows with empty cells in column 1
> Dim rng As Range
> Dim LRow As Long
>
> On Error Resume Next
> LRow = Cells(Rows.Count, 1).End(xlUp).Row
> Set rng = ActiveSheet.Range("A1:A" & LRow).SpecialCells(xlBlanks)
> On Error GoTo 0
> If Not rng Is Nothing Then
> rng.EntireRow.Delete
> End If
> End Sub
>
> Mike F
> "Scott" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I get an error "Cannot use that command on overlapping selections". It
>>doesn't like " rng.EntireRow.Delete"
>>
>>
>> "Gord Dibben" <gorddibbATshawDOTca> wrote in message
>> news:(E-Mail Removed)...
>>> Sub DeleteRowsWithEmptyColumn1()
>>> ' deletes rows with empty cells in column 1
>>> Dim rng As Range
>>> On Error Resume Next
>>> Set rng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) _
>>> .SpecialCells(xlBlanks)
>>> On Error GoTo 0
>>> If Not rng Is Nothing Then
>>> rng.EntireRow.Delete
>>> End If
>>> End Sub
>>>
>>>
>>> Gord Dibben MS Excel MVP
>>>
>>> On Fri, 29 Sep 2006 19:39:09 -0500, "Scott" <(E-Mail Removed)>
>>> wrote:
>>>
>>>>My below sub below corectly deletes any rows that have empty cells
>>>>within a
>>>>hard-coded range of A1:A150. What I'd like to do is to search the entire
>>>>range of cells containing values and delete any rows that have empty
>>>>column
>>>>1 cells.
>>>>
>>>>It would achieve the same reults as my current code, but I could get rid
>>>>of
>>>>my hard coded reference. I never will know how many rows my spreadsheet
>>>>will
>>>>be and would like to avoid hard-code reference.
>>>>
>>>>Can someone help me re-write my code to achieve this?
>>>>
>>>>
>>>>CODE **********************
>>>>
>>>>Sub DeleteRowsWithEmptyColumn1()
>>>> ' deletes rows with empty cells in column 1
>>>> Dim rng As Range
>>>> On Error Resume Next
>>>> Set rng = ActiveSheet.Range("A1:A150").SpecialCells(xlBlanks)
>>>> On Error GoTo 0
>>>> If Not rng Is Nothing Then
>>>> rng.EntireRow.Delete
>>>> End If
>>>>End Sub
>>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Paul B
Guest
Posts: n/a
 
      2nd Oct 2006
Scott, the code from Gord and Mike work for me, here is another way

Sub Delete_blank_Column1()
On Error Resume Next
Intersect(Range("A:A"), ActiveSheet.UsedRange) _
..SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003


"Scott" <(E-Mail Removed)> wrote in message
news:O0%23CY%(E-Mail Removed)...
> for some reason, the code still isn't deleting my row with empty cell in
> column 1. Can you check it again?
>
> "Mike Fogleman" <(E-Mail Removed)> wrote in message
> news:3OCdnU9t4psH-(E-Mail Removed)...
> > You need to find the last row as a variable:
> >
> > Sub DeleteRowsWithEmptyColumn1()
> > ' deletes rows with empty cells in column 1
> > Dim rng As Range
> > Dim LRow As Long
> >
> > On Error Resume Next
> > LRow = Cells(Rows.Count, 1).End(xlUp).Row
> > Set rng = ActiveSheet.Range("A1:A" & LRow).SpecialCells(xlBlanks)
> > On Error GoTo 0
> > If Not rng Is Nothing Then
> > rng.EntireRow.Delete
> > End If
> > End Sub
> >
> > Mike F
> > "Scott" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >>I get an error "Cannot use that command on overlapping selections". It
> >>doesn't like " rng.EntireRow.Delete"
> >>
> >>
> >> "Gord Dibben" <gorddibbATshawDOTca> wrote in message
> >> news:(E-Mail Removed)...
> >>> Sub DeleteRowsWithEmptyColumn1()
> >>> ' deletes rows with empty cells in column 1
> >>> Dim rng As Range
> >>> On Error Resume Next
> >>> Set rng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) _
> >>> .SpecialCells(xlBlanks)
> >>> On Error GoTo 0
> >>> If Not rng Is Nothing Then
> >>> rng.EntireRow.Delete
> >>> End If
> >>> End Sub
> >>>
> >>>
> >>> Gord Dibben MS Excel MVP
> >>>
> >>> On Fri, 29 Sep 2006 19:39:09 -0500, "Scott" <(E-Mail Removed)>
> >>> wrote:
> >>>
> >>>>My below sub below corectly deletes any rows that have empty cells
> >>>>within a
> >>>>hard-coded range of A1:A150. What I'd like to do is to search the

entire
> >>>>range of cells containing values and delete any rows that have empty
> >>>>column
> >>>>1 cells.
> >>>>
> >>>>It would achieve the same reults as my current code, but I could get

rid
> >>>>of
> >>>>my hard coded reference. I never will know how many rows my

spreadsheet
> >>>>will
> >>>>be and would like to avoid hard-code reference.
> >>>>
> >>>>Can someone help me re-write my code to achieve this?
> >>>>
> >>>>
> >>>>CODE **********************
> >>>>
> >>>>Sub DeleteRowsWithEmptyColumn1()
> >>>> ' deletes rows with empty cells in column 1
> >>>> Dim rng As Range
> >>>> On Error Resume Next
> >>>> Set rng = ActiveSheet.Range("A1:A150").SpecialCells(xlBlanks)
> >>>> On Error GoTo 0
> >>>> If Not rng Is Nothing Then
> >>>> rng.EntireRow.Delete
> >>>> End If
> >>>>End Sub
> >>>>
> >>>
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      2nd Oct 2006
Thanks. That method took care of business.

"Paul B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Scott, the code from Gord and Mike work for me, here is another way
>
> Sub Delete_blank_Column1()
> On Error Resume Next
> Intersect(Range("A:A"), ActiveSheet.UsedRange) _
> .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
> On Error GoTo 0
> End Sub
>
> --
> Paul B
> Always backup your data before trying something new
> Please post any response to the newsgroups so others can benefit from it
> Feedback on answers is always appreciated!
> Using Excel 2002 & 2003
>
>
> "Scott" <(E-Mail Removed)> wrote in message
> news:O0%23CY%(E-Mail Removed)...
>> for some reason, the code still isn't deleting my row with empty cell in
>> column 1. Can you check it again?
>>
>> "Mike Fogleman" <(E-Mail Removed)> wrote in message
>> news:3OCdnU9t4psH-(E-Mail Removed)...
>> > You need to find the last row as a variable:
>> >
>> > Sub DeleteRowsWithEmptyColumn1()
>> > ' deletes rows with empty cells in column 1
>> > Dim rng As Range
>> > Dim LRow As Long
>> >
>> > On Error Resume Next
>> > LRow = Cells(Rows.Count, 1).End(xlUp).Row
>> > Set rng = ActiveSheet.Range("A1:A" & LRow).SpecialCells(xlBlanks)
>> > On Error GoTo 0
>> > If Not rng Is Nothing Then
>> > rng.EntireRow.Delete
>> > End If
>> > End Sub
>> >
>> > Mike F
>> > "Scott" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >>I get an error "Cannot use that command on overlapping selections". It
>> >>doesn't like " rng.EntireRow.Delete"
>> >>
>> >>
>> >> "Gord Dibben" <gorddibbATshawDOTca> wrote in message
>> >> news:(E-Mail Removed)...
>> >>> Sub DeleteRowsWithEmptyColumn1()
>> >>> ' deletes rows with empty cells in column 1
>> >>> Dim rng As Range
>> >>> On Error Resume Next
>> >>> Set rng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) _
>> >>> .SpecialCells(xlBlanks)
>> >>> On Error GoTo 0
>> >>> If Not rng Is Nothing Then
>> >>> rng.EntireRow.Delete
>> >>> End If
>> >>> End Sub
>> >>>
>> >>>
>> >>> Gord Dibben MS Excel MVP
>> >>>
>> >>> On Fri, 29 Sep 2006 19:39:09 -0500, "Scott" <(E-Mail Removed)>
>> >>> wrote:
>> >>>
>> >>>>My below sub below corectly deletes any rows that have empty cells
>> >>>>within a
>> >>>>hard-coded range of A1:A150. What I'd like to do is to search the

> entire
>> >>>>range of cells containing values and delete any rows that have empty
>> >>>>column
>> >>>>1 cells.
>> >>>>
>> >>>>It would achieve the same reults as my current code, but I could get

> rid
>> >>>>of
>> >>>>my hard coded reference. I never will know how many rows my

> spreadsheet
>> >>>>will
>> >>>>be and would like to avoid hard-code reference.
>> >>>>
>> >>>>Can someone help me re-write my code to achieve this?
>> >>>>
>> >>>>
>> >>>>CODE **********************
>> >>>>
>> >>>>Sub DeleteRowsWithEmptyColumn1()
>> >>>> ' deletes rows with empty cells in column 1
>> >>>> Dim rng As Range
>> >>>> On Error Resume Next
>> >>>> Set rng = ActiveSheet.Range("A1:A150").SpecialCells(xlBlanks)
>> >>>> On Error GoTo 0
>> >>>> If Not rng Is Nothing Then
>> >>>> rng.EntireRow.Delete
>> >>>> End If
>> >>>>End Sub
>> >>>>
>> >>>
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
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
How do I delete rows where cells are empty Stan Microsoft Excel Misc 2 2nd Jan 2008 05:49 AM
Re: delete rows with empty cells Don Guillett Microsoft Excel Misc 2 19th Dec 2006 05:14 PM
Re: delete rows with empty cells Nick Hodge Microsoft Excel Misc 5 19th Dec 2006 04:44 PM
Delete rows with empty cells in columns B&C =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Misc 3 18th Mar 2006 12:15 AM
How can I delete empty table rows or cells? =?Utf-8?B?Qm9iIExvbmc=?= Microsoft Word Document Management 1 20th Sep 2004 07:41 PM


Features
 

Advertising
 

Newsgroups
 


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