View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Bit of a VBA problem.

Dim rngA as Range, rngB as Range, rng as Range
Dim cell as Range, sAddr as String
with workbooks("WorkbookA.xls").Worksheets("Sheet1")
set rngA = .range(.Cells(1,1),.Cells(1,1).end(xldown))
End with
With workbooks("WorkbookB.xls").Worksheets("Sheet1")
set rngB = .Range(.Cells(1,3),.Cells(1,3).End(xldown))
End with
for each cell in rngA
set rng = rngB.Find(What:=cell.Value, _
After:=rngB(rngB.count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
if not rng is nothing then
sAddr = rng.address
do
if rng.offset(0,1).Value = _
cell.offset(0,1).Value then
rng.offset(0,-2).Value = 5000
end if
set rng = rngB.FindNext(rng)
loop until rng.Address = sAddr
End if
Next

--
Regards,
Tom Ogilvy


"mazzarin" wrote in
message ...

Okay, after stepping through the code a bit I've established that it
runs all the way down to the bottom. On its way, it sets sAddr as
Customer A.


Code:
--------------------

Loop Until rng.Address = sAddr

--------------------


Then, it jumps back to


Code:
--------------------

If rng.Offset(0, 1).Value = _
cell.Offset(0, 1).Value Then
rng.Offset(0, -2).Value = 5000
End If
Set rng = rngB.FindNext(rng)
Loop Until rng.Address = sAddr

--------------------


and doesn't change any values on the worksheet, nor does it update its
own variables.

This continues constantly, no matter how many times I step through it.
Going to work on it a bit more.


--
mazzarin
------------------------------------------------------------------------
mazzarin's Profile:

http://www.excelforum.com/member.php...o&userid=32186
View this thread: http://www.excelforum.com/showthread...hreadid=519316