Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Check the conditions in "Q:Q"

It worked ok in 2003.

Rather than scan whole Column which would probably take a very long time in
2007 - i would limit search upto last used cell.

See if adjusted code helps

Sub CheckRange()
Dim Cell As Range
Dim ws As Worksheet
Dim lr As Long

Set ws = ActiveSheet

With ws

lr = .Cells(.Rows.Count, "Q").End(xlUp).Row


For Each Cell In .Range("Q1:Q" & lr)

If Cell.Value = _
dte And Cell.Offset(0, -6).Value = "XXX" Then

x = x + 1

ElseIf Cell.Value = _
dte And Cell.Offset(0, -6).Value = "YYY" Then

y = y + 1

ElseIf Cell.Value = _
dte And Cell.Offset(0, -6).Value = "ZZZ" Then

z = z + 1

ElseIf Cell.Value = _
dte And Cell.Offset(0, -6).Value = "XYZ" Then

i = i + 1

End If


Next Cell

End With


End Sub



jb


"SR" wrote:

I have tried this alredy, but it was not working. After running this the
workbook is not responding and I have to close the file.
Any other suggestion?

"SR" wrote:

Hi,

I need a loop which will check the below conditions in all the cell (even if
the cells are blank") in column Q ("Q:Q")

If ActiveCell.Value = dte And ActiveCell.Offset(0, -6).Value = "XXX" Then
x = x + 1
ElseIf ActiveCell.Value = dte And ActiveCell.Offset(0,
-6).Value = "YYY" Then
y = y + 1
ElseIf ActiveCell.Value = dte And ActiveCell.Offset(0,
-6).Value = "ZZZ" Then
z = z + 1
ElseIf ActiveCell.Value = dte And ActiveCell.Offset(0,
-6).Value = "XYZ" Then
i = i + 1

else

ActiveCell.Offset(1, 0).Select

Thanks in advance.

SR

  #2   Report Post  
Posted to microsoft.public.excel.programming
SR SR is offline
external usenet poster
 
Posts: 18
Default Check the conditions in "Q:Q"

Hey John,

Thanks a lot for your valuable help nd time.There was some tipo with my code
.. Its working fine now.
Have a Great Day.


"john" wrote:

not sure what you are doing as this line €œlr = .Cells(.Rows.Count,
"Q").End(xlUp).Row€
finds the last used cell from bottom of worksheet up so should not be
affected if some cells are blank between Q1 & last row.

I tested data as described & code worked its way to last populated cell in Q.

as an alternative try changing this line:

For Each Cell In .Range("Q1:Q" & lr)

to this


For Each Cell In .UsedRange

(do not omit the period €œ.€ (full stop) in front of UsedRange)

& see if that helps.

Also, Mike has kindly responded along similar lines, take note of his
suggestions.

--
jb


"SR" wrote:

Hi John,

If I am using last used cell loop is closing at "Q2" as "Q3" is blank. But I
have data in Q4 and the loop needs to be run in Q4 also..

can we make all the blank cell in column Q to some other value before the
loop starts and make it blank again once the loop finish running?

"john" wrote:

It worked ok in 2003.

Rather than scan whole Column which would probably take a very long time in
2007 - i would limit search upto last used cell.

See if adjusted code helps

Sub CheckRange()
Dim Cell As Range
Dim ws As Worksheet
Dim lr As Long

Set ws = ActiveSheet

With ws

lr = .Cells(.Rows.Count, "Q").End(xlUp).Row


For Each Cell In .Range("Q1:Q" & lr)

If Cell.Value = _
dte And Cell.Offset(0, -6).Value = "XXX" Then

x = x + 1

ElseIf Cell.Value = _
dte And Cell.Offset(0, -6).Value = "YYY" Then

y = y + 1

ElseIf Cell.Value = _
dte And Cell.Offset(0, -6).Value = "ZZZ" Then

z = z + 1

ElseIf Cell.Value = _
dte And Cell.Offset(0, -6).Value = "XYZ" Then

i = i + 1

End If


Next Cell

End With


End Sub



jb


"SR" wrote:

I have tried this alredy, but it was not working. After running this the
workbook is not responding and I have to close the file.
Any other suggestion?

"SR" wrote:

Hi,

I need a loop which will check the below conditions in all the cell (even if
the cells are blank") in column Q ("Q:Q")

If ActiveCell.Value = dte And ActiveCell.Offset(0, -6).Value = "XXX" Then
x = x + 1
ElseIf ActiveCell.Value = dte And ActiveCell.Offset(0,
-6).Value = "YYY" Then
y = y + 1
ElseIf ActiveCell.Value = dte And ActiveCell.Offset(0,
-6).Value = "ZZZ" Then
z = z + 1
ElseIf ActiveCell.Value = dte And ActiveCell.Offset(0,
-6).Value = "XYZ" Then
i = i + 1

else

ActiveCell.Offset(1, 0).Select

Thanks in advance.

SR

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
Check the conditions in "Q:Q" john Excel Programming 0 December 13th 09 08:47 PM
Check if cells contain the word "Thailand", return "TRUE" ali Excel Worksheet Functions 7 September 14th 07 09:53 AM
How to check if one of the conditions returns "true"? Isito Excel Programming 4 September 6th 06 12:25 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
create links to check boxes marked "good" fair"and "bad" pjb Excel Worksheet Functions 3 April 20th 06 02:17 AM


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

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"