ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Conditionally Delete Cells From Named Range (https://www.excelbanter.com/excel-programming/311597-conditionally-delete-cells-named-range.html)

[email protected]

Conditionally Delete Cells From Named Range
 
I have a 1-D named range "MYRANGE" in a column
I'd like to loop through this range, comparing
each of the values in this range to a specific value.
If the values are not the same, I want to delete that cell
from the named range and then move the other cells up.

Here's what I have so far:

Set rMyRange = Range("MYRANGE")
testvalue = "100"
rMyRange.Select
For Each cell in Selection
If left(Cstr(cell.value),3) < testvalue Then
???? Select that cell ????
Selection.Delete Shift:=xlUp
End If
Next cell

Thanks in advance...


Tom Ogilvy

Conditionally Delete Cells From Named Range
 
Dim rng as Range, rMyRange as Range
Dim testValue as String, cell as Range
Set rMyRange = Range("MYRANGE")
testvalue = "100"
rMyRange.Select
For Each cell in Selection
If left(Cstr(cell.value),3) < testvalue Then
if rng is nothing then
set rng = cell
else
set rng = union(rng,cell)
end if
End If
Next cell
if not rng is nothing then
rng.Delete Shift:=xlshiftUp
End if


--
Regards,
Tom Ogilvy



" wrote in message
oups.com...
I have a 1-D named range "MYRANGE" in a column
I'd like to loop through this range, comparing
each of the values in this range to a specific value.
If the values are not the same, I want to delete that cell
from the named range and then move the other cells up.

Here's what I have so far:

Set rMyRange = Range("MYRANGE")
testvalue = "100"
rMyRange.Select
For Each cell in Selection
If left(Cstr(cell.value),3) < testvalue Then
???? Select that cell ????
Selection.Delete Shift:=xlUp
End If
Next cell

Thanks in advance...




[email protected]

Conditionally Delete Cells From Named Range
 
Thanks Tom



All times are GMT +1. The time now is 05:27 AM.

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