Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default how do i write an if/and/then statement to compare adjacent cells? TIA greatly



i need to run a for/next loop for a selection which i started like
this:

Range("f3:l9").Select
For Each i In Selection

i need to compare the data in f3 with the date in g3 and h3, then f3
with the two cells above it, then the two cells below it and the two
cells to the left of it, for four different comparisions for each cell
in the selection..

if i.value = 1 and (next cell right) = 1 and (two cells right) = 0
then c=c+1

if i.value = 1 and (next cell up) = 1 and (two cells up) = 0 then
c=c+1
etc....

do i use OFFSET to look at the next cell? if so, how do i write that?

also, after "THEN c=c+1" , i need to take a value exactly 9 cells
below the selected cell and copy that value to another variable. Do I
use OFFSET for that?

if the 3 statements are true, then c=c+1 AND x = (value of 9 cells
below f3 + a constant).

I hope this is clear.
I appreciate your help. Everyone in this group has been phenomenal.
Thanks again,
Jason K.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default how do i write an if/and/then statement to compare adjacent cells? TIA greatly

Not totally clear, but here is a start

For Each i In Range("F3:F9")
If i.Value =1 And i.Offset(0,1).Value = 1 And i.Offset(0,2).Value =
0 Then _
c = c + 1
newVar = c + i.Offset(9,0).Value
End If
Next i

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"JasonK" wrote in message
...


i need to run a for/next loop for a selection which i started like
this:

Range("f3:l9").Select
For Each i In Selection

i need to compare the data in f3 with the date in g3 and h3, then f3
with the two cells above it, then the two cells below it and the two
cells to the left of it, for four different comparisions for each cell
in the selection..

if i.value = 1 and (next cell right) = 1 and (two cells right) = 0
then c=c+1

if i.value = 1 and (next cell up) = 1 and (two cells up) = 0 then
c=c+1
etc....

do i use OFFSET to look at the next cell? if so, how do i write that?

also, after "THEN c=c+1" , i need to take a value exactly 9 cells
below the selected cell and copy that value to another variable. Do I
use OFFSET for that?

if the 3 statements are true, then c=c+1 AND x = (value of 9 cells
below f3 + a constant).

I hope this is clear.
I appreciate your help. Everyone in this group has been phenomenal.
Thanks again,
Jason K.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default how do i write an if/and/then statement to compare adjacent cells? TIA greatly

thank you Bob.
I appreciate the help.
jasonK

On Thu, 21 Sep 2006 09:51:25 +0100, "Bob Phillips"
wrote:

Not totally clear, but here is a start

For Each i In Range("F3:F9")
If i.Value =1 And i.Offset(0,1).Value = 1 And i.Offset(0,2).Value =
0 Then _
c = c + 1
newVar = c + i.Offset(9,0).Value
End If
Next i


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default how do i write an if/and/then statement to compare adjacent cells? TIA greatly

Hi
Offset will do.

e.g
Dim cell as range
For each cell in Range("F3:L9")
With cell
If .Value = 1 and .offset(0,1).value = 1 and .offset(0, 2).Value = 0
then
c = c+1
end if
end with
next cell

to go one to the right use .offset(0, -1)
to go one down use .offset(1, 0)
to go one up use .offset(-1, 0)

you can also use offset to take you out of your range.

regards
Paul

JasonK wrote:
i need to run a for/next loop for a selection which i started like
this:

Range("f3:l9").Select
For Each i In Selection

i need to compare the data in f3 with the date in g3 and h3, then f3
with the two cells above it, then the two cells below it and the two
cells to the left of it, for four different comparisions for each cell
in the selection..

if i.value = 1 and (next cell right) = 1 and (two cells right) = 0
then c=c+1

if i.value = 1 and (next cell up) = 1 and (two cells up) = 0 then
c=c+1
etc....

do i use OFFSET to look at the next cell? if so, how do i write that?

also, after "THEN c=c+1" , i need to take a value exactly 9 cells
below the selected cell and copy that value to another variable. Do I
use OFFSET for that?

if the 3 statements are true, then c=c+1 AND x = (value of 9 cells
below f3 + a constant).

I hope this is clear.
I appreciate your help. Everyone in this group has been phenomenal.
Thanks again,
Jason K.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default how do i write an if/and/then statement to compare adjacent cells? TIA greatly

oops, typo
to go one to the LEFT use .offset(0, -1)

regards
Paul

wrote:
Hi
Offset will do.

e.g
Dim cell as range
For each cell in Range("F3:L9")
With cell
If .Value = 1 and .offset(0,1).value = 1 and .offset(0, 2).Value = 0
then
c = c+1
end if
end with
next cell

to go one to the right use .offset(0, -1)
to go one down use .offset(1, 0)
to go one up use .offset(-1, 0)

you can also use offset to take you out of your range.

regards
Paul

JasonK wrote:
i need to run a for/next loop for a selection which i started like
this:

Range("f3:l9").Select
For Each i In Selection

i need to compare the data in f3 with the date in g3 and h3, then f3
with the two cells above it, then the two cells below it and the two
cells to the left of it, for four different comparisions for each cell
in the selection..

if i.value = 1 and (next cell right) = 1 and (two cells right) = 0
then c=c+1

if i.value = 1 and (next cell up) = 1 and (two cells up) = 0 then
c=c+1
etc....

do i use OFFSET to look at the next cell? if so, how do i write that?

also, after "THEN c=c+1" , i need to take a value exactly 9 cells
below the selected cell and copy that value to another variable. Do I
use OFFSET for that?

if the 3 statements are true, then c=c+1 AND x = (value of 9 cells
below f3 + a constant).

I hope this is clear.
I appreciate your help. Everyone in this group has been phenomenal.
Thanks again,
Jason K.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default how do i write an if/and/then statement to compare adjacent cells? TIA greatly

Thank you Paul -
i thought offset was the way, just didn't know how to do it.
thanks again,
jasonK.

On 21 Sep 2006 02:00:14 -0700, wrote:

oops, typo
to go one to the LEFT use .offset(0, -1)

regards
Paul

wrote:
Hi
Offset will do.

e.g
Dim cell as range
For each cell in Range("F3:L9")
With cell
If .Value = 1 and .offset(0,1).value = 1 and .offset(0, 2).Value = 0
then
c = c+1
end if
end with
next cell

to go one to the right use .offset(0, -1)
to go one down use .offset(1, 0)
to go one up use .offset(-1, 0)

you can also use offset to take you out of your range.

regards
Paul

JasonK wrote:
i need to run a for/next loop for a selection which i started like
this:

Range("f3:l9").Select
For Each i In Selection

i need to compare the data in f3 with the date in g3 and h3, then f3
with the two cells above it, then the two cells below it and the two
cells to the left of it, for four different comparisions for each cell
in the selection..

if i.value = 1 and (next cell right) = 1 and (two cells right) = 0
then c=c+1

if i.value = 1 and (next cell up) = 1 and (two cells up) = 0 then
c=c+1
etc....

do i use OFFSET to look at the next cell? if so, how do i write that?

also, after "THEN c=c+1" , i need to take a value exactly 9 cells
below the selected cell and copy that value to another variable. Do I
use OFFSET for that?

if the 3 statements are true, then c=c+1 AND x = (value of 9 cells
below f3 + a constant).

I hope this is clear.
I appreciate your help. Everyone in this group has been phenomenal.
Thanks again,
Jason K.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default how do i write an if/and/then statement to compare adjacent cells? thanks Paul & Bob - worked perfectly

thanks again you guys, i got it running in just a few minutes.
i still need more help with some other things, but i'm going to try to
work them out on my own first.

i'm jazzed.

thanks again,
jasonK




On 21 Sep 2006 02:00:14 -0700, wrote:

oops, typo
to go one to the LEFT use .offset(0, -1)

regards
Paul

wrote:
Hi
Offset will do.

e.g
Dim cell as range
For each cell in Range("F3:L9")
With cell
If .Value = 1 and .offset(0,1).value = 1 and .offset(0, 2).Value = 0
then
c = c+1
end if
end with
next cell

to go one to the right use .offset(0, -1)
to go one down use .offset(1, 0)
to go one up use .offset(-1, 0)

you can also use offset to take you out of your range.

regards
Paul

JasonK wrote:
i need to run a for/next loop for a selection which i started like
this:

Range("f3:l9").Select
For Each i In Selection

i need to compare the data in f3 with the date in g3 and h3, then f3
with the two cells above it, then the two cells below it and the two
cells to the left of it, for four different comparisions for each cell
in the selection..

if i.value = 1 and (next cell right) = 1 and (two cells right) = 0
then c=c+1

if i.value = 1 and (next cell up) = 1 and (two cells up) = 0 then
c=c+1
etc....

do i use OFFSET to look at the next cell? if so, how do i write that?

also, after "THEN c=c+1" , i need to take a value exactly 9 cells
below the selected cell and copy that value to another variable. Do I
use OFFSET for that?

if the 3 statements are true, then c=c+1 AND x = (value of 9 cells
below f3 + a constant).

I hope this is clear.
I appreciate your help. Everyone in this group has been phenomenal.
Thanks again,
Jason K.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default how do i write an if/and/then statement to compare adjacent cells? thanks Paul & Bob - worked perfectly

Start a new thread for that Jason, then we can ditch this one.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"JasonK" wrote in message
...
thanks again you guys, i got it running in just a few minutes.
i still need more help with some other things, but i'm going to try to
work them out on my own first.

i'm jazzed.

thanks again,
jasonK




On 21 Sep 2006 02:00:14 -0700, wrote:

oops, typo
to go one to the LEFT use .offset(0, -1)

regards
Paul

wrote:
Hi
Offset will do.

e.g
Dim cell as range
For each cell in Range("F3:L9")
With cell
If .Value = 1 and .offset(0,1).value = 1 and .offset(0, 2).Value = 0
then
c = c+1
end if
end with
next cell

to go one to the right use .offset(0, -1)
to go one down use .offset(1, 0)
to go one up use .offset(-1, 0)

you can also use offset to take you out of your range.

regards
Paul

JasonK wrote:
i need to run a for/next loop for a selection which i started like
this:

Range("f3:l9").Select
For Each i In Selection

i need to compare the data in f3 with the date in g3 and h3, then f3
with the two cells above it, then the two cells below it and the two
cells to the left of it, for four different comparisions for each

cell
in the selection..

if i.value = 1 and (next cell right) = 1 and (two cells right) = 0
then c=c+1

if i.value = 1 and (next cell up) = 1 and (two cells up) = 0 then
c=c+1
etc....

do i use OFFSET to look at the next cell? if so, how do i write that?

also, after "THEN c=c+1" , i need to take a value exactly 9 cells
below the selected cell and copy that value to another variable. Do I
use OFFSET for that?

if the 3 statements are true, then c=c+1 AND x = (value of 9 cells
below f3 + a constant).

I hope this is clear.
I appreciate your help. Everyone in this group has been phenomenal.
Thanks again,
Jason K.




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
compare 2 column cells and return the adjacent columns cells data of the cell trebor57 Excel Worksheet Functions 1 February 1st 11 02:54 PM
Compare 1 cell to column of cells returning adjacent cells info? Mr. Fine Excel Worksheet Functions 1 April 15th 10 07:36 PM
Compare adjacent fields in adjacent rows Quimera New Users to Excel 6 May 30th 08 11:36 AM
compare adjacent cells and calculate averages Marquismarce Excel Worksheet Functions 5 May 17th 06 09:46 AM
Compare 2 cells values with one IF statement jbsand1001 Excel Worksheet Functions 1 June 9th 05 06:15 PM


All times are GMT +1. The time now is 02:55 AM.

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"