#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default loops

Hi,

I am struggling with loops again, just can not get this right. can you
please assist me once again.

I have the following piece of code which checks the customer and product
with a range to see if that combination already exist, thanks to Joel.
I have now realised that I need to enter a qty for price breaks so the loop
will need to check, customer, product and qty.

I had this code

With historyWks
Customer = Range("D11")
Product = Range("D9")
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product Then
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With

So based on my own logic I thought if I would need to add the new criteria
of Qty
as follows


With historyWks
Customer = Range("D11")
Product = Range("D9")
Qty = Range("D14") 'THIS IS A NEW LINE'
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product & C.Offset(0, 5) = Qty Then 'THIS LINE IS
CHANGED'
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With


Appreciate your help.

Thank you

Elaine

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default loops

Hi,

Sorry to take up your time but I think I have found the issue

I have used & when I should of used And

Well it seems to work now.


"winnie123" wrote:

Hi,

I am struggling with loops again, just can not get this right. can you
please assist me once again.

I have the following piece of code which checks the customer and product
with a range to see if that combination already exist, thanks to Joel.
I have now realised that I need to enter a qty for price breaks so the loop
will need to check, customer, product and qty.

I had this code

With historyWks
Customer = Range("D11")
Product = Range("D9")
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product Then
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With

So based on my own logic I thought if I would need to add the new criteria
of Qty
as follows


With historyWks
Customer = Range("D11")
Product = Range("D9")
Qty = Range("D14") 'THIS IS A NEW LINE'
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product & C.Offset(0, 5) = Qty Then 'THIS LINE IS
CHANGED'
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With


Appreciate your help.

Thank you

Elaine

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default loops

You were real close, but no cigar.

from
If C.Offset(0, 2) = Product & C.Offset(0, 5) = Qty Then

to
If C.Offset(0, 2) = Product And C.Offset(0, 5) = Qty Then


the "&" is used to connect two string together like

A = "Boys"
B = "Girls"
c = A & "and" & B which gives the string "Boys and Girls"

The logic AND is used to connect two logicals

a = False and False which gives False
a = False and True which gives False
a = True and False which gives False
a = True and True which gives True

Your statement
If (C.Offset(0, 2) = Product) And (C.Offset(0, 5) = Qty) Then

This line is a combination of two equalities

C.Offset(0, 2) = Product will results in either TRUE or FALSE
C.Offset(0, 5) = Qty will result in either TRUE or FALSE

Now you want two check that both equalities are true
"winnie123" wrote:

Hi,

I am struggling with loops again, just can not get this right. can you
please assist me once again.

I have the following piece of code which checks the customer and product
with a range to see if that combination already exist, thanks to Joel.
I have now realised that I need to enter a qty for price breaks so the loop
will need to check, customer, product and qty.

I had this code

With historyWks
Customer = Range("D11")
Product = Range("D9")
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product Then
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With

So based on my own logic I thought if I would need to add the new criteria
of Qty
as follows


With historyWks
Customer = Range("D11")
Product = Range("D9")
Qty = Range("D14") 'THIS IS A NEW LINE'
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product & C.Offset(0, 5) = Qty Then 'THIS LINE IS
CHANGED'
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With


Appreciate your help.

Thank you

Elaine

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default loops

Thanks Joel for the clarification and explanation.
Guess I will just have to have cigerette's :-)



"joel" wrote:

You were real close, but no cigar.

from
If C.Offset(0, 2) = Product & C.Offset(0, 5) = Qty Then

to
If C.Offset(0, 2) = Product And C.Offset(0, 5) = Qty Then


the "&" is used to connect two string together like

A = "Boys"
B = "Girls"
c = A & "and" & B which gives the string "Boys and Girls"

The logic AND is used to connect two logicals

a = False and False which gives False
a = False and True which gives False
a = True and False which gives False
a = True and True which gives True

Your statement
If (C.Offset(0, 2) = Product) And (C.Offset(0, 5) = Qty) Then

This line is a combination of two equalities

C.Offset(0, 2) = Product will results in either TRUE or FALSE
C.Offset(0, 5) = Qty will result in either TRUE or FALSE

Now you want two check that both equalities are true
"winnie123" wrote:

Hi,

I am struggling with loops again, just can not get this right. can you
please assist me once again.

I have the following piece of code which checks the customer and product
with a range to see if that combination already exist, thanks to Joel.
I have now realised that I need to enter a qty for price breaks so the loop
will need to check, customer, product and qty.

I had this code

With historyWks
Customer = Range("D11")
Product = Range("D9")
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product Then
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With

So based on my own logic I thought if I would need to add the new criteria
of Qty
as follows


With historyWks
Customer = Range("D11")
Product = Range("D9")
Qty = Range("D14") 'THIS IS A NEW LINE'
Found = False

With .Columns("C")
Set C = .Find(what:=Customer, LookIn:=xlValues, _
lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'check column E for product
If C.Offset(0, 2) = Product & C.Offset(0, 5) = Qty Then 'THIS LINE IS
CHANGED'
Found = True
Exit Do
End If
Set C = .FindNext(After:=C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With


Appreciate your help.

Thank you

Elaine

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
WHILE AND FOR LOOPS paul[_17_] Excel Programming 2 July 21st 07 11:12 PM
Loops fugfug[_2_] Excel Programming 3 July 8th 05 10:53 AM
for each loops adncmm1980[_3_] Excel Programming 1 October 4th 04 12:56 PM
Do Loops Sue[_5_] Excel Programming 1 May 20th 04 07:51 PM
Loops Tom Ogilvy Excel Programming 0 July 18th 03 05:20 PM


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