Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help Needed Fixing Code !!!!!!!!!!

I need someone to take a look at this code for me and telling me what I am
doing wrong.
What I am trying to do is delete any row where this condition is true:
c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed" And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
In other words, if the values in these cells are anything but complete,
delete the entire row.

For Each c In Worksheets("Ready for DDS").Range("B2:B" & SL_lRow).Cells
If c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed"
And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Delete
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Help Needed Fixing Code !!!!!!!!!!

Ayo,

The code works perfectly provided the cells do contain the text Completed.

if it isn't working for you; and clearly it isn't, then a couple of things
to consider.

1. The string comparison is case sensitive.
2, Do you really mean that ALL of these cells must not contain Completed
because that's what the code is saying i.e to be deleted ALL 4 cells must not
contain the text string.
3. have you dimmed rngAll as a range

Lastly tell us what result you getting.
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Ayo" wrote:

I need someone to take a look at this code for me and telling me what I am
doing wrong.
What I am trying to do is delete any row where this condition is true:
c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed" And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
In other words, if the values in these cells are anything but complete,
delete the entire row.

For Each c In Worksheets("Ready for DDS").Range("B2:B" & SL_lRow).Cells
If c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed"
And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Delete

  #3   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help Needed Fixing Code !!!!!!!!!!

This is the entire sub:

Sub buildDDS_SITELIST()
Dim SL_lRow As Long, c As Range, rngAll As Range
SL_lRow = Worksheets("Sites Task List").Cells(Rows.Count,
"A").End(xlUp).Row

Worksheets("Sites Task List").Range("A2:J" & SL_lRow).Copy
Worksheets("Ready for DDS").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Range("B2").Select
Worksheets("Sites Task List").Range("S2:S" & SL_lRow).Copy
Worksheets("Ready for DDS").Select
Range("K2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

For Each c In Worksheets("Ready for DDS").Range("B2:B" & SL_lRow).Cells
If c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed"
And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Delete
End Sub

I am getting cells with Open, InProgress and Not Required in the cells,
while I only want cells with Completed.

"Mike H" wrote:

Ayo,

The code works perfectly provided the cells do contain the text Completed.

if it isn't working for you; and clearly it isn't, then a couple of things
to consider.

1. The string comparison is case sensitive.
2, Do you really mean that ALL of these cells must not contain Completed
because that's what the code is saying i.e to be deleted ALL 4 cells must not
contain the text string.
3. have you dimmed rngAll as a range

Lastly tell us what result you getting.
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Ayo" wrote:

I need someone to take a look at this code for me and telling me what I am
doing wrong.
What I am trying to do is delete any row where this condition is true:
c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed" And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
In other words, if the values in these cells are anything but complete,
delete the entire row.

For Each c In Worksheets("Ready for DDS").Range("B2:B" & SL_lRow).Cells
If c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed"
And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Delete

  #4   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help Needed Fixing Code !!!!!!!!!!

I mean, if anyone of these cells contain anything other than "Completed",
delete the entire row. But if all the cells contains "Completed" keep the row.

"Mike H" wrote:

Ayo,

The code works perfectly provided the cells do contain the text Completed.

if it isn't working for you; and clearly it isn't, then a couple of things
to consider.

1. The string comparison is case sensitive.
2, Do you really mean that ALL of these cells must not contain Completed
because that's what the code is saying i.e to be deleted ALL 4 cells must not
contain the text string.
3. have you dimmed rngAll as a range

Lastly tell us what result you getting.
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Ayo" wrote:

I need someone to take a look at this code for me and telling me what I am
doing wrong.
What I am trying to do is delete any row where this condition is true:
c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed" And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
In other words, if the values in these cells are anything but complete,
delete the entire row.

For Each c In Worksheets("Ready for DDS").Range("B2:B" & SL_lRow).Cells
If c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed"
And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Delete

  #5   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help Needed Fixing Code !!!!!!!!!!

I got it!!!. All I need was to change:
c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed" And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
to
c.Offset(0, 2) < "Completed" Or c.Offset(0, 3) < "Completed" Or _
c.Offset(0, 4) < "Completed" Or c.Offset(0, 5) < "Completed"
Thanks for all the help.

"Mike H" wrote:

Ayo,

The code works perfectly provided the cells do contain the text Completed.

if it isn't working for you; and clearly it isn't, then a couple of things
to consider.

1. The string comparison is case sensitive.
2, Do you really mean that ALL of these cells must not contain Completed
because that's what the code is saying i.e to be deleted ALL 4 cells must not
contain the text string.
3. have you dimmed rngAll as a range

Lastly tell us what result you getting.
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Ayo" wrote:

I need someone to take a look at this code for me and telling me what I am
doing wrong.
What I am trying to do is delete any row where this condition is true:
c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed" And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
In other words, if the values in these cells are anything but complete,
delete the entire row.

For Each c In Worksheets("Ready for DDS").Range("B2:B" & SL_lRow).Cells
If c.Offset(0, 2) < "Completed" And c.Offset(0, 3) < "Completed"
And _
c.Offset(0, 4) < "Completed" And c.Offset(0, 5) < "Completed"
Then
If rngAll Is Nothing Then
Set rngAll = c
Else
Set rngAll = Union(rngAll, c)
End If
End If
Next c
If Not rngAll Is Nothing Then rngAll.EntireRow.Delete

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
vb code help needed Phil Excel Programming 4 January 10th 07 04:21 AM
Help Please - last bit of code needed Mark Dullingham Excel Programming 4 May 6th 06 12:33 AM
Fixing VBA code to better suit concatenating needs!! Sandwiches2 Excel Programming 1 March 15th 06 02:32 AM
fixing code timmy64 - ExcelForums.com Excel Programming 2 July 4th 05 09:48 AM


All times are GMT +1. The time now is 07:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"