ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   So close! Problems with Loop (https://www.excelbanter.com/excel-programming/322442-so-close-problems-loop.html)

Linking to specific cells in pivot table

So close! Problems with Loop
 
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

PaulD

So close! Problems with Loop
 

"Linking to specific cells in pivot table"
crosoft.com wrote in
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

So close! Problems with Loop
 
Thanks Paul. How do I verify what x and z are when the loop ends?

"PaulD" wrote:


"Linking to specific cells in pivot table"
crosoft.com wrote in
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




PaulD

So close! Problems with Loop
 

"Linking to specific cells in pivot table"
crosoft.com wrote in
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




All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com