ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   HELP modifying macro to delete rows if more than 1 condition met & (https://www.excelbanter.com/excel-programming/440101-help-modifying-macro-delete-rows-if-more-than-1-condition-met.html)

Mayte

HELP modifying macro to delete rows if more than 1 condition met &
 
I got his code and it works fine but wondering if it can be modified to
delete not only rows that have "TRUE" in column in A but other 3 or 4
different calues in column B...

Sub UPDATE_TENURE()
Dim MyRange, MyRange1 As Range
Dim LastRow As Long
Set Sht = Sheets("Agent Tenure")
LastRow = Sht.Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Sht.Range("A1:A" & 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

Rick Rothstein

HELP modifying macro to delete rows if more than 1 condition met &
 
Yes, it can be modified. You didn't say what your other conditions are, but
generally you would OR them into this line of code...

If UCase(c.Value) = "TRUE" Then

For example...

If UCase(c.Value) = "TRUE" Or UCase(c.Value) = "NewCondition" Then

Just keep OR'ing your new conditions in the same way I added the
"NewCondition" above.

--
Rick (MVP - Excel)


"Mayte" wrote in message
...
I got his code and it works fine but wondering if it can be modified to
delete not only rows that have "TRUE" in column in A but other 3 or 4
different calues in column B...

Sub UPDATE_TENURE()
Dim MyRange, MyRange1 As Range
Dim LastRow As Long
Set Sht = Sheets("Agent Tenure")
LastRow = Sht.Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Sht.Range("A1:A" & 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




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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com