PC Review


Reply
Thread Tools Rate Thread

Delete Rows with Loop Statement

 
 
Brennan
Guest
Posts: n/a
 
      18th Feb 2008
I have the following code. I am trying to get this code to delete all of the
rows that are not equal to the "name." When I turn on the screen updates I
can see it doing what I want it to do, but then it wigs out at the end and
turns into a white screen. Any help would be appreciated. Thanks

Brennan

Do

If ActiveCell <> name Then

ActiveCell.EntireRow.Delete

End If

Loop Until IsEmpty(ActiveCell.Offset(0, -2))

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      18th Feb 2008

If ActiveCell <> name Then

If rng Is Nothing then

Set rng = activecell.entirerow
Else

Set rng = Union(rng, ActiveCell.EntireRow)
End If
End If

Loop Until IsEmpty(ActiveCell.Offset(0, -2))

If Not rng Is Nothing Then rng.Delete

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Brennan" <(E-Mail Removed)> wrote in message
news:B7CD2FE1-16B0-4214-AA21-(E-Mail Removed)...
>I have the following code. I am trying to get this code to delete all of
>the
> rows that are not equal to the "name." When I turn on the screen updates
> I
> can see it doing what I want it to do, but then it wigs out at the end and
> turns into a white screen. Any help would be appreciated. Thanks
>
> Brennan
>
> Do
>
> If ActiveCell <> name Then
>
> ActiveCell.EntireRow.Delete
>
> End If
>
> Loop Until IsEmpty(ActiveCell.Offset(0, -2))
>
> .Calculation = xlCalculationAutomatic
> .ScreenUpdating = True



 
Reply With Quote
 
Brennan
Guest
Posts: n/a
 
      18th Feb 2008

Hi Bob,

When I run the code, the sheet keeps blowing up on me. Here is the final
version of the code that I used. Please let me know what I need to change.
Thanks again!

rivate Sub MNGName_Change()
Dim name As String
Dim rng As range

With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False

Sheets("Sheet1").Select
range("A1").Select

ActiveCell = Me.MNGName.Value
name = ActiveCell

Unload Splash

Sheets("Outlook").Select
range("c3").Select

Do
If ActiveCell <> name Then
If rng Is Nothing Then
Set rng = ActiveCell.EntireRow
Else
Set rng = Union(rng, ActiveCell.EntireRow)
End If
End If
Loop Until IsEmpty(ActiveCell.Offset(0, -2))
If Not rng Is Nothing Then rng.Delete

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True

End With


End Sub

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      19th Feb 2008
I had to strip it down to test it, I don't have the form. I had to add a
line to move the activecell on but this version worked for me

Private Sub MNGName_Change()
Dim name As String
Dim rng As Range

With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

Sheets("Sheet1").Select
Range("A1").Select

ActiveCell.Value = Me.MNGName.Value
name = ActiveCell.Value

Unload Splash

Sheets("Outlook").Select
Range("C3").Select

Do
If ActiveCell.Value <> name Then

If rng Is Nothing Then

Set rng = ActiveCell.EntireRow
Else

Set rng = Union(rng, ActiveCell.EntireRow)
End If
End If

ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))

If Not rng Is Nothing Then rng.Delete

With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Brennan" <(E-Mail Removed)> wrote in message
news:C0E41770-A305-47DD-BF17-(E-Mail Removed)...
>
> Hi Bob,
>
> When I run the code, the sheet keeps blowing up on me. Here is the final
> version of the code that I used. Please let me know what I need to
> change.
> Thanks again!
>
> rivate Sub MNGName_Change()
> Dim name As String
> Dim rng As range
>
> With Application
> .Calculation = xlCalculationManual
> .ScreenUpdating = False
>
> Sheets("Sheet1").Select
> range("A1").Select
>
> ActiveCell = Me.MNGName.Value
> name = ActiveCell
>
> Unload Splash
>
> Sheets("Outlook").Select
> range("c3").Select
>
> Do
> If ActiveCell <> name Then
> If rng Is Nothing Then
> Set rng = ActiveCell.EntireRow
> Else
> Set rng = Union(rng, ActiveCell.EntireRow)
> End If
> End If
> Loop Until IsEmpty(ActiveCell.Offset(0, -2))
> If Not rng Is Nothing Then rng.Delete
>
> .Calculation = xlCalculationAutomatic
> .ScreenUpdating = True
>
> End With
>
>
> End Sub
>



 
Reply With Quote
 
Brennan
Guest
Posts: n/a
 
      19th Feb 2008
It worked - thanks for your help!

B

"Brennan" wrote:

> I have the following code. I am trying to get this code to delete all of the
> rows that are not equal to the "name." When I turn on the screen updates I
> can see it doing what I want it to do, but then it wigs out at the end and
> turns into a white screen. Any help would be appreciated. Thanks
>
> Brennan
>
> Do
>
> If ActiveCell <> name Then
>
> ActiveCell.EntireRow.Delete
>
> End If
>
> Loop Until IsEmpty(ActiveCell.Offset(0, -2))
>
> .Calculation = xlCalculationAutomatic
> .ScreenUpdating = True

 
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
help with loop to delete rows =?Utf-8?B?Q2hyaXN0eQ==?= Microsoft Excel Programming 7 22nd Feb 2007 04:06 PM
How to Delete Rows in Excel In a Do Loop indraneel Microsoft Excel Worksheet Functions 6 15th Sep 2006 09:51 AM
Macro/Loop If Statement Help -delete the row with the specific te =?Utf-8?B?QnJpY2t0b3A=?= Microsoft Excel Programming 5 28th Oct 2005 09:50 PM
loop to delete rows... Froglegz Microsoft Excel Programming 5 1st Aug 2004 09:56 PM
How do I delete rows and columns in With With End Loop? Bob Benjamin Microsoft Excel Programming 3 16th Nov 2003 12:26 AM


Features
 

Advertising
 

Newsgroups
 


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