Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Macro to Delete Rows if true HELP!

I got this code from another answer and it works ok when I call it from the
activesheet ("Agent Tenure") but I need to call it from another sheet named
"Terminations"... please help????

Sub UPDATE_TENURE()
Dim myrange, MyRange1 As Range
lastrow = Cells(Rows.Count, "N").End(xlUp).Row
Set myrange = Sheets("Agent Tenure").Range("N1:N" & lastrow)
For Each c In myrange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro to Delete Rows if true HELP!

Hi,

Try it like this

Sub UPDATE_TENURE()
Dim MyRange, MyRange1 As Range
Dim LastRow As Long
Set Sht = Sheets("Agent Tenure")
LastRow = Sht.Cells(Rows.Count, "N").End(xlUp).Row
Stop
Set MyRange = Sht.Range("N1:N" & LastRow)
For Each c In MyRange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mayte" wrote:

I got this code from another answer and it works ok when I call it from the
activesheet ("Agent Tenure") but I need to call it from another sheet named
"Terminations"... please help????

Sub UPDATE_TENURE()
Dim myrange, MyRange1 As Range
lastrow = Cells(Rows.Count, "N").End(xlUp).Row
Set myrange = Sheets("Agent Tenure").Range("N1:N" & lastrow)
For Each c In myrange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro to Delete Rows if true HELP!

Hmmm,

left a stop command in try this instead

Sub UPDATE_TENURE()
Dim MyRange, MyRange1 As Range
Dim LastRow As Long
Set Sht = Sheets("Agent Tenure")
LastRow = Sht.Cells(Rows.Count, "N").End(xlUp).Row
Set MyRange = Sht.Range("N1:N" & LastRow)
For Each c In MyRange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

Hi,

Try it like this

Sub UPDATE_TENURE()
Dim MyRange, MyRange1 As Range
Dim LastRow As Long
Set Sht = Sheets("Agent Tenure")
LastRow = Sht.Cells(Rows.Count, "N").End(xlUp).Row
Stop
Set MyRange = Sht.Range("N1:N" & LastRow)
For Each c In MyRange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mayte" wrote:

I got this code from another answer and it works ok when I call it from the
activesheet ("Agent Tenure") but I need to call it from another sheet named
"Terminations"... please help????

Sub UPDATE_TENURE()
Dim myrange, MyRange1 As Range
lastrow = Cells(Rows.Count, "N").End(xlUp).Row
Set myrange = Sheets("Agent Tenure").Range("N1:N" & lastrow)
For Each c In myrange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Macro to Delete Rows if true HELP!

I got an error. the code stops at "stop" and doens't go forward

"Mike H" wrote:

Hi,

Try it like this

Sub UPDATE_TENURE()
Dim MyRange, MyRange1 As Range
Dim LastRow As Long
Set Sht = Sheets("Agent Tenure")
LastRow = Sht.Cells(Rows.Count, "N").End(xlUp).Row
Stop
Set MyRange = Sht.Range("N1:N" & LastRow)
For Each c In MyRange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mayte" wrote:

I got this code from another answer and it works ok when I call it from the
activesheet ("Agent Tenure") but I need to call it from another sheet named
"Terminations"... please help????

Sub UPDATE_TENURE()
Dim myrange, MyRange1 As Range
lastrow = Cells(Rows.Count, "N").End(xlUp).Row
Set myrange = Sheets("Agent Tenure").Range("N1:N" & lastrow)
For Each c In myrange
If UCase(c.Value) = "TRUE" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Macro to Delete Rows if true HELP!

ACE!! it works now -- thanks!!!
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
Macro to delete rows Ken G Excel Programming 4 February 2nd 10 05:49 AM
Macro to delete 2 rows every 500 rows [email protected] Excel Programming 3 February 3rd 08 01:52 PM
Macro to delete rows Tasha Excel Programming 18 September 28th 07 02:47 AM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM


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

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"