Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row of cells in range based on condition

I have written this to delete the row of cells within the selected range when
the value "Rock Breaking" is in a cell in the row.

It is however deleting the entire row.
How do I stop this?


Sub tmp3()

Dim rngOfData As Range
Dim Cell As Range

With Sheets("Daily Report")
Set rngOfData = .Range("DA20:DE29")
End With

For Each Cell In rngOfData
If Cell.Value = "Rock Breaking" Then
Cell.Row.Delete
End If
Next Cell

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Delete row of cells in range based on condition

It is doing what you have told it to do in the code. Where you have:

Cell.Row.Delete

If you only want to delete the contents of a portion of the row, then
for columns A - D:

Range(Cell.Offset(0, -3. Cell.Address).ClearContents

"Kirsty" wrote:

I have written this to delete the row of cells within the selected range when
the value "Rock Breaking" is in a cell in the row.

It is however deleting the entire row.
How do I stop this?


Sub tmp3()

Dim rngOfData As Range
Dim Cell As Range

With Sheets("Daily Report")
Set rngOfData = .Range("DA20:DE29")
End With

For Each Cell In rngOfData
If Cell.Value = "Rock Breaking" Then
Cell.Row.Delete
End If
Next Cell

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row of cells in range based on condition

I have tried that now I am getting an error that states Expected: list
separator or ) before the Cell.Address

"JLGWhiz" wrote:

It is doing what you have told it to do in the code. Where you have:

Cell.Row.Delete

If you only want to delete the contents of a portion of the row, then
for columns A - D:

Range(Cell.Offset(0, -3. Cell.Address).ClearContents

"Kirsty" wrote:

I have written this to delete the row of cells within the selected range when
the value "Rock Breaking" is in a cell in the row.

It is however deleting the entire row.
How do I stop this?


Sub tmp3()

Dim rngOfData As Range
Dim Cell As Range

With Sheets("Daily Report")
Set rngOfData = .Range("DA20:DE29")
End With

For Each Cell In rngOfData
If Cell.Value = "Rock Breaking" Then
Cell.Row.Delete
End If
Next Cell

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Delete row of cells in range based on condition

Try this. Notice the dot placement

Sub deletepartofrowif()
With Sheets("Daily Report")
Set rng = .Range("DA20:DE29")
For Each c In rng
If c = "Rock Breaking" then
.Range(.Cells(c.Row, "da"),.Cells(c.Row, "de")).ClearContents
End If
Next c
End With
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Kirsty" wrote in message
...
I have written this to delete the row of cells within the selected range
when
the value "Rock Breaking" is in a cell in the row.

It is however deleting the entire row.
How do I stop this?


Sub tmp3()

Dim rngOfData As Range
Dim Cell As Range

With Sheets("Daily Report")
Set rngOfData = .Range("DA20:DE29")
End With

For Each Cell In rngOfData
If Cell.Value = "Rock Breaking" Then
Cell.Row.Delete
End If
Next Cell

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Delete row of cells in range based on condition

Sorry about that. Should have been:

Range(Cell.Offset(0, -3), Cell.Address).ClearContents

You would have to modify the Range parameters if you want cells different
than A thru D of that row.


"Kirsty" wrote:

I have tried that now I am getting an error that states Expected: list
separator or ) before the Cell.Address

"JLGWhiz" wrote:

It is doing what you have told it to do in the code. Where you have:

Cell.Row.Delete

If you only want to delete the contents of a portion of the row, then
for columns A - D:

Range(Cell.Offset(0, -3. Cell.Address).ClearContents

"Kirsty" wrote:

I have written this to delete the row of cells within the selected range when
the value "Rock Breaking" is in a cell in the row.

It is however deleting the entire row.
How do I stop this?


Sub tmp3()

Dim rngOfData As Range
Dim Cell As Range

With Sheets("Daily Report")
Set rngOfData = .Range("DA20:DE29")
End With

For Each Cell In rngOfData
If Cell.Value = "Rock Breaking" Then
Cell.Row.Delete
End If
Next Cell

End Sub

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
how to delete a row based on a condition ya Excel Programming 2 December 17th 08 03:59 PM
Delete Range Cell Based on Condition Jean Excel Programming 7 May 30th 07 10:19 PM
Highlighting Range of Cells based on another cell with 5 condition Alex Excel Programming 6 November 10th 06 06:45 AM
Delete Cells Based on Range STEVEB Excel Programming 6 July 28th 05 05:37 PM
Delete Columns based on a condition Joel Mills Excel Programming 3 August 6th 04 07:21 PM


All times are GMT +1. The time now is 07:00 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"