Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I want to delete all cells in a range that have "x" in
them. I have used the following code: For Each Cell In Sheets("CDPTS").Range("B1:B363") If Cell.Value = "x" Then Cell.Delete Shift:=xlUp End If Next Cell However, this doesn't delete them all? I repeated the code several times and it finally does get them all. Is there a more reliable code to do my job? SDC |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
SDC,
Build up a range that includes all the x values before doing the deletion: Sub DeleteXs() Dim myRange As Range Dim myCell As Range For Each myCell In Sheets("CDPTS").Range("B1:B363") If myCell.Value = "x" Then If myRange Is Nothing Then Set myRange = myCell Else Set myRange = Union(myRange, myCell) End If End If Next myCell myRange.Delete Shift:=xlUp End Sub HTH, Bernie Excel MVP "scrabtree23" wrote in message ... I want to delete all cells in a range that have "x" in them. I have used the following code: However, this doesn't delete them all? I repeated the code several times and it finally does get them all. Is there a more reliable code to do my job? SDC |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try,
for i = 363 to 1 step -1 If Sheets("CDPTS").Range("B" & i).Value = "x" Then Sheets("CDPTS").Range("B" & i).Delete Shift:=xlUp End If Next Cell Cecil "scrabtree23" wrote in message ... I want to delete all cells in a range that have "x" in them. I have used the following code: For Each Cell In Sheets("CDPTS").Range("B1:B363") If Cell.Value = "x" Then Cell.Delete Shift:=xlUp End If Next Cell However, this doesn't delete them all? I repeated the code several times and it finally does get them all. Is there a more reliable code to do my job? SDC |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how can I disable "cutting cells" and "drag and drop "in excel ? | Excel Worksheet Functions | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
DELETE CELLS w/ "DIV/0" MACRO | Charts and Charting in Excel | |||
Excel "Move or Copy" and "Delete" sheet functions | Excel Worksheet Functions | |||
Any way to use toolbar button to delete cells and move cells "up"? | Excel Discussion (Misc queries) |