So close! Problems with Loop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi - I'm almost there! For some reason, the loop I wrote stops before it
should (it should stop when variable x = variable z). Can someone take a
look and let me know if they think they know why? The loop starts half way
down -- I put in the code for the whole Macro as it may help you understand
what I'm doing here. Any help is appreciated!!

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/23/2005 by Cisco Systems, Inc.
'

'
Dim x As Range
Dim y As Range
Dim z As Range
Dim Myrange As Range

Worksheets("Aurora").Activate
Range("A1").Select

Cells.Find(What:="MAX PRICE AFTER ADJUSTMENTS:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Set x = ActiveWindow.RangeSelection
Set y = ActiveCell.Offset(0, 1)
Set z = ActiveCell.Offset(0, 1)

ActiveCell.Offset(1, 1).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Set Myrange = ActiveWindow.RangeSelection

For Each c In Myrange
c.Value = c.Value / 500
Next


Do While x <> z

y.Select

Cells.Find(What:="MAX PRICE AFTER ADJUSTMENTS:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Set z = ActiveWindow.RangeSelection
Set y = ActiveCell.Offset(0, 1)

ActiveCell.Offset(1, 1).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Set Myrange = ActiveWindow.RangeSelection

For Each c In Myrange
c.Value = c.Value / 500
Next
Loop

End Sub
 
"Linking to specific cells in pivot table"
message : Hi - I'm almost there! For some reason, the loop I wrote stops before it
: should (it should stop when variable x = variable z). Can someone take a
: look and let me know if they think they know why? The loop starts half
way
: down -- I put in the code for the whole Macro as it may help you
understand
: what I'm doing here. Any help is appreciated!!
:
<snip>:

: Do While x <> z

have you tried Do Until x = z
did you verify what x and z were when the loop ended?

Paul D
 
"Linking to specific cells in pivot table"
message : Thanks Paul. How do I verify what x and z are when the loop ends?
:

one way is to use a breakpoint at the end of the loop then look at the value
for each

Paul D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top