Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete two records together with looping


I am having touble using looping to remove records that contain a D when
two are together using the following:

Dim constantCells As Range
Dim Cell As Range
Set constantCells =
Sheets("Roster").Range("A:A).SpecialCells(xlConsta nts)
For Each Cell In constantCells
If Cell.Value 0 Then
If Cell.Offset(0, 2) = "D" Then
Cell.Offset(0, 0).Resize(6).EntireRow.Delete
End If
End If
Next Cell

I know the problem is after the record is deleted the next cell is
skipped because the next command is Next Cell.

Can someone help me come up with the VBA code that deletes records when
the desired records are one after the other?

Thanks a million. mikeburg


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=514655

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Delete two records together with looping

I tried to fix your macro. But your macro appeared to:
1) Go through cells in Column(A).
2) When find a cell which is non-zero, then
3) If the cell 2 columns to the right contains a "D", delete the entire row.

The tasks looks strange to me... But, anyway, try the macro below:

Sub clean_rows()
Dim constantCells As Range
Dim tmp As Single
Dim tmp_address As String

tmp_address =
Worksheets("Roster").Range("A1").CurrentRegion.Col umns(1).Address(False,
False)

With Worksheets("Roster").Range(tmp_address)
If .Cells.Count = 1 And .Cells(1).Value = "" Then Exit Sub
For tmp = .Cells.Count To 1 Step -1
If .Cells(tmp).Value < 0 And .Cells(tmp).Offset(0, 2) = "D" Then
.Cells(tmp).EntireRow.Delete
End If
Next
End With
End Sub

Regards,
Edwin Tam

http://www.vonixx.com




"mikeburg" wrote:


I am having touble using looping to remove records that contain a D when
two are together using the following:

Dim constantCells As Range
Dim Cell As Range
Set constantCells =
Sheets("Roster").Range("A:A).SpecialCells(xlConsta nts)
For Each Cell In constantCells
If Cell.Value 0 Then
If Cell.Offset(0, 2) = "D" Then
Cell.Offset(0, 0).Resize(6).EntireRow.Delete
End If
End If
Next Cell

I know the problem is after the record is deleted the next cell is
skipped because the next command is Next Cell.

Can someone help me come up with the VBA code that deletes records when
the desired records are one after the other?

Thanks a million. mikeburg


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=514655


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete two records together with looping


Yes, you are correct on your assumptions, except the delete should be 6
rows.

I couldn't get the above code to delete all the records with a "D" even
after modifying it to delete 6 rows.

I was hoping to merely modify my code. Is there a way to have it to
work from the bottom up?

In any event, I would like to keep it as simple as possible because I
am still learning.

Thanks a million. mikeburg


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=514655

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
Delete records when certain records have duplicate column data JVroom New Users to Excel 1 January 26th 09 06:23 PM
looping a 'find and delete' code matpj[_18_] Excel Programming 1 November 8th 05 01:14 PM
Looping down a Range to delete entire row sportsguy Excel Programming 3 July 1st 05 04:50 PM
urgent. looping thru all records and applynig formula to get new results shirley Excel Programming 2 April 29th 04 04:32 AM
Looping Through Records. Diana[_5_] Excel Programming 6 December 2nd 03 05:40 PM


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