PC Review


Reply
Thread Tools Rate Thread

Anouther loop question

 
 
=?Utf-8?B?Q2hyaXN0eQ==?=
Guest
Posts: n/a
 
      22nd Feb 2007
WOW - those last answers not only worked well but were som mcuh faster that
my code - I LOVE this forum!!!

Below is anouther loop I am using - it works but is slow and inefficient -
any suggestions for improvement would be muxh appreciated. Not sure how to
impliment the 'used range' and 'no selection' tips here.

Sub ProcessCountHistory()
Dim i As Integer

For i = 7 To 7500
Cells(i, 15).Select
If ActiveCell.Value = "" Then
If ActiveCell.Offset(-1, 0).Value = "YES" Then
If ActiveCell.Offset(-2, 0).Value = "YES" Then
If ActiveCell.Offset(-3, 0).Value = "YES" Then
ActiveCell.Offset(0, -2).Value = "Count required?"
ActiveCell.Value = "NO"
Else
ActiveCell.Offset(0, -2).Value = "Count required?"
ActiveCell.Value = "YES"
End If
Else
ActiveCell.Offset(0, -2).Value = "Count required?"
ActiveCell.Value = "YES"
End If
Else
ActiveCell.Offset(0, -2).Value = "Count required?"
ActiveCell.Value = "YES"
End If
End If
Next i
Range("a1").Select
End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      22nd Feb 2007

set rng1 = rng.offset(0,-3).Resize(,3)

Sub ProcessCountHistory()
Dim rng as Range, rng1 as range, cell as Range

set rng = Range(cells(7,15),cells(rows.count,15).End(xlup))

On error Resume Next
set rng1 = rng.specialCells(xlBlanks)
On error goto 0

if rng1 is nothing then exit sub

For each cell in rng1
If Cell.Offset(-1, 0).Value = "YES" Then
If Cell.Offset(-2, 0).Value = "YES" Then
If Cell.Offset(-3, 0).Value = "YES" Then
Cell.Offset(0, -2).Value = "Count required?"
Cell.Value = "NO"
Else
Cell.Offset(0, -2).Value = "Count required?"
Cell.Value = "YES"
End If
Else
Cell.Offset(0, -2).Value = "Count required?"
Cell.Value = "YES"
End If
Else
Cell.Offset(0, -2).Value = "Count required?"
Cell.Value = "YES"

End If
Next cell
Range("a1").Select
End Sub

This assumes that the cells in column O are actually blank

if the cells appear blank because there is a formula like
=if(condition,"",number result)

so all non blank appearing cells are numeric you could change
xlblank to

xlformulas,xltextvalues

--
Regards,
Tom Ogilvy



"Christy" wrote:

> WOW - those last answers not only worked well but were som mcuh faster that
> my code - I LOVE this forum!!!
>
> Below is anouther loop I am using - it works but is slow and inefficient -
> any suggestions for improvement would be muxh appreciated. Not sure how to
> impliment the 'used range' and 'no selection' tips here.
>
> Sub ProcessCountHistory()
> Dim i As Integer
>
> For i = 7 To 7500
> Cells(i, 15).Select
> If ActiveCell.Value = "" Then
> If ActiveCell.Offset(-1, 0).Value = "YES" Then
> If ActiveCell.Offset(-2, 0).Value = "YES" Then
> If ActiveCell.Offset(-3, 0).Value = "YES" Then
> ActiveCell.Offset(0, -2).Value = "Count required?"
> ActiveCell.Value = "NO"
> Else
> ActiveCell.Offset(0, -2).Value = "Count required?"
> ActiveCell.Value = "YES"
> End If
> Else
> ActiveCell.Offset(0, -2).Value = "Count required?"
> ActiveCell.Value = "YES"
> End If
> Else
> ActiveCell.Offset(0, -2).Value = "Count required?"
> ActiveCell.Value = "YES"
> End If
> End If
> Next i
> Range("a1").Select
> End Sub

 
Reply With Quote
 
=?Utf-8?B?Q2hyaXN0eQ==?=
Guest
Posts: n/a
 
      22nd Feb 2007
Thanks Tom! It works fine but it wouldn't let me use the line above the Sub
ProcessCountHistory() line. I commented thaty out and it seems to work great.
Did I need to put that line above all my subs in the module?

"Tom Ogilvy" wrote:

>
> set rng1 = rng.offset(0,-3).Resize(,3)
>
> Sub ProcessCountHistory()
> Dim rng as Range, rng1 as range, cell as Range
>
> set rng = Range(cells(7,15),cells(rows.count,15).End(xlup))
>
> On error Resume Next
> set rng1 = rng.specialCells(xlBlanks)
> On error goto 0
>
> if rng1 is nothing then exit sub
>
> For each cell in rng1
> If Cell.Offset(-1, 0).Value = "YES" Then
> If Cell.Offset(-2, 0).Value = "YES" Then
> If Cell.Offset(-3, 0).Value = "YES" Then
> Cell.Offset(0, -2).Value = "Count required?"
> Cell.Value = "NO"
> Else
> Cell.Offset(0, -2).Value = "Count required?"
> Cell.Value = "YES"
> End If
> Else
> Cell.Offset(0, -2).Value = "Count required?"
> Cell.Value = "YES"
> End If
> Else
> Cell.Offset(0, -2).Value = "Count required?"
> Cell.Value = "YES"
>
> End If
> Next cell
> Range("a1").Select
> End Sub
>
> This assumes that the cells in column O are actually blank
>
> if the cells appear blank because there is a formula like
> =if(condition,"",number result)
>
> so all non blank appearing cells are numeric you could change
> xlblank to
>
> xlformulas,xltextvalues
>
> --
> Regards,
> Tom Ogilvy
>
>
>
> "Christy" wrote:
>
> > WOW - those last answers not only worked well but were som mcuh faster that
> > my code - I LOVE this forum!!!
> >
> > Below is anouther loop I am using - it works but is slow and inefficient -
> > any suggestions for improvement would be muxh appreciated. Not sure how to
> > impliment the 'used range' and 'no selection' tips here.
> >
> > Sub ProcessCountHistory()
> > Dim i As Integer
> >
> > For i = 7 To 7500
> > Cells(i, 15).Select
> > If ActiveCell.Value = "" Then
> > If ActiveCell.Offset(-1, 0).Value = "YES" Then
> > If ActiveCell.Offset(-2, 0).Value = "YES" Then
> > If ActiveCell.Offset(-3, 0).Value = "YES" Then
> > ActiveCell.Offset(0, -2).Value = "Count required?"
> > ActiveCell.Value = "NO"
> > Else
> > ActiveCell.Offset(0, -2).Value = "Count required?"
> > ActiveCell.Value = "YES"
> > End If
> > Else
> > ActiveCell.Offset(0, -2).Value = "Count required?"
> > ActiveCell.Value = "YES"
> > End If
> > Else
> > ActiveCell.Offset(0, -2).Value = "Count required?"
> > ActiveCell.Value = "YES"
> > End If
> > End If
> > Next i
> > Range("a1").Select
> > End Sub

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      23rd Feb 2007
That was just a stray line that got copied by accident.

--
Regards,
Tom Ogilvy


"Christy" <(E-Mail Removed)> wrote in message
news:ED77672B-9804-4E54-A780-(E-Mail Removed)...
> Thanks Tom! It works fine but it wouldn't let me use the line above the
> Sub
> ProcessCountHistory() line. I commented thaty out and it seems to work
> great.
> Did I need to put that line above all my subs in the module?
>
> "Tom Ogilvy" wrote:
>
>>
>> set rng1 = rng.offset(0,-3).Resize(,3)
>>
>> Sub ProcessCountHistory()
>> Dim rng as Range, rng1 as range, cell as Range
>>
>> set rng = Range(cells(7,15),cells(rows.count,15).End(xlup))
>>
>> On error Resume Next
>> set rng1 = rng.specialCells(xlBlanks)
>> On error goto 0
>>
>> if rng1 is nothing then exit sub
>>
>> For each cell in rng1
>> If Cell.Offset(-1, 0).Value = "YES" Then
>> If Cell.Offset(-2, 0).Value = "YES" Then
>> If Cell.Offset(-3, 0).Value = "YES" Then
>> Cell.Offset(0, -2).Value = "Count required?"
>> Cell.Value = "NO"
>> Else
>> Cell.Offset(0, -2).Value = "Count required?"
>> Cell.Value = "YES"
>> End If
>> Else
>> Cell.Offset(0, -2).Value = "Count required?"
>> Cell.Value = "YES"
>> End If
>> Else
>> Cell.Offset(0, -2).Value = "Count required?"
>> Cell.Value = "YES"
>>
>> End If
>> Next cell
>> Range("a1").Select
>> End Sub
>>
>> This assumes that the cells in column O are actually blank
>>
>> if the cells appear blank because there is a formula like
>> =if(condition,"",number result)
>>
>> so all non blank appearing cells are numeric you could change
>> xlblank to
>>
>> xlformulas,xltextvalues
>>
>> --
>> Regards,
>> Tom Ogilvy
>>
>>
>>
>> "Christy" wrote:
>>
>> > WOW - those last answers not only worked well but were som mcuh faster
>> > that
>> > my code - I LOVE this forum!!!
>> >
>> > Below is anouther loop I am using - it works but is slow and
>> > inefficient -
>> > any suggestions for improvement would be muxh appreciated. Not sure how
>> > to
>> > impliment the 'used range' and 'no selection' tips here.
>> >
>> > Sub ProcessCountHistory()
>> > Dim i As Integer
>> >
>> > For i = 7 To 7500
>> > Cells(i, 15).Select
>> > If ActiveCell.Value = "" Then
>> > If ActiveCell.Offset(-1, 0).Value = "YES" Then
>> > If ActiveCell.Offset(-2, 0).Value = "YES" Then
>> > If ActiveCell.Offset(-3, 0).Value = "YES" Then
>> > ActiveCell.Offset(0, -2).Value = "Count
>> > required?"
>> > ActiveCell.Value = "NO"
>> > Else
>> > ActiveCell.Offset(0, -2).Value = "Count
>> > required?"
>> > ActiveCell.Value = "YES"
>> > End If
>> > Else
>> > ActiveCell.Offset(0, -2).Value = "Count required?"
>> > ActiveCell.Value = "YES"
>> > End If
>> > Else
>> > ActiveCell.Offset(0, -2).Value = "Count required?"
>> > ActiveCell.Value = "YES"
>> > End If
>> > End If
>> > Next i
>> > Range("a1").Select
>> > End Sub



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The 7 nested If() function Limitation. Is there anouther way? =?Utf-8?B?RE1C?= Microsoft Excel Worksheet Functions 9 15th Jan 2006 12:06 AM
Moving selective data from one sheet to anouther handymanmd Microsoft Excel Discussion 1 8th Sep 2005 03:05 AM
In excel, importing from anouther sheet background colors will no. =?Utf-8?B?aW1wb3J0aW5nIGJhY2tncm91bmRz?= Microsoft Excel Worksheet Functions 0 20th Apr 2005 09:38 PM
copy appointments from one calendar to anouther? Graham Microsoft Outlook Calendar 1 21st Jun 2004 08:04 PM
Anouther question to answer Richard W Microsoft Windows 2000 DNS 0 23rd Nov 2003 11:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.