Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gum Gum is offline
external usenet poster
 
Posts: 30
Default Nested Do While Loops

I have been trying to get a nested Do While Loop and I need to find out where
I went wrong. The snippet of the procedure is as follows:

Sub control()
Dim Target1 As Integer
Dim Target2 As Integer
Dim TTarget As Integer
Dim Net As Integer
Dim ExNet As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer


BTarget = Sheets("Sheet1").Range("H3")
STarget = Sheets("Sheet1").Range("H4")
ExNet = Sheets("Sheet1").Range("N3")
TTarget = Target1 + Target2
While TTarget < 0 And i < 100
If TTarget ExNet Then
Net = TTarget - ExNet
While Net 0 And j < 100
Sheets("Sheet1").Range("G3") = 1
Sheets("Sheet1").Range("G4") = 0
j = j + 1
Wend
Else:
If ExNet TTarget Then
Net = Exnet - TTarget
While Net 0 And k < 100
Sheets("Sheet1").Range("G3") = 0
Sheets("Sheet1").Range("G4") = 1
k = k + 1
Wend
End If
i = i + 1
Wend
End If
End Sub

I placed the i,j, and k just to control the maximum times the loop occurs so
that it would not be indefinite.
I am getting errors with the 'Wend without While' compile error when the
above procedure is run.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Nested Do While Loops

Just fixing the syntax

Sub control()
Dim Target1 As Integer
Dim Target2 As Integer
Dim TTarget As Integer
Dim Net As Integer
Dim ExNet As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer


BTarget = Sheets("Sheet1").Range("H3")
STarget = Sheets("Sheet1").Range("H4")
ExNet = Sheets("Sheet1").Range("N3")
TTarget = Target1 + Target2
While TTarget < 0 And i < 100

If TTarget ExNet Then

Net = TTarget - ExNet
While Net 0 And j < 100

Sheets("Sheet1").Range("G3") = 1
Sheets("Sheet1").Range("G4") = 0
j = j + 1
Wend
Else
If ExNet TTarget Then

Net = ExNet - TTarget
While Net 0 And k < 100

Sheets("Sheet1").Range("G3") = 0
Sheets("Sheet1").Range("G4") = 1
k = k + 1
Wend
End If

i = i + 1
End If
Wend
End Sub


--
__________________________________
HTH

Bob

"Gum" wrote in message
...
I have been trying to get a nested Do While Loop and I need to find out
where
I went wrong. The snippet of the procedure is as follows:

Sub control()
Dim Target1 As Integer
Dim Target2 As Integer
Dim TTarget As Integer
Dim Net As Integer
Dim ExNet As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer


BTarget = Sheets("Sheet1").Range("H3")
STarget = Sheets("Sheet1").Range("H4")
ExNet = Sheets("Sheet1").Range("N3")
TTarget = Target1 + Target2
While TTarget < 0 And i < 100
If TTarget ExNet Then
Net = TTarget - ExNet
While Net 0 And j < 100
Sheets("Sheet1").Range("G3") = 1
Sheets("Sheet1").Range("G4") = 0
j = j + 1
Wend
Else:
If ExNet TTarget Then
Net = Exnet - TTarget
While Net 0 And k < 100
Sheets("Sheet1").Range("G3") = 0
Sheets("Sheet1").Range("G4") = 1
k = k + 1
Wend
End If
i = i + 1
Wend
End If
End Sub

I placed the i,j, and k just to control the maximum times the loop occurs
so
that it would not be indefinite.
I am getting errors with the 'Wend without While' compile error when the
above procedure is run.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Nested Do While Loops

i think your last "End If" should come before your last "Wend".
i added more spaces to your coding to indent it in a more exaggerated
manner & that's what i come up with.
:)
susan


On Nov 20, 12:14*pm, Gum wrote:
I have been trying to get a nested Do While Loop and I need to find out where
I went wrong. *The snippet of the procedure is as follows:

Sub control()
Dim Target1 As Integer
Dim Target2 As Integer
Dim TTarget As Integer
Dim Net As Integer
Dim ExNet As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer

BTarget = Sheets("Sheet1").Range("H3")
STarget = Sheets("Sheet1").Range("H4")
ExNet = Sheets("Sheet1").Range("N3")
TTarget = Target1 + Target2

While TTarget < 0 And i < 100
* * If TTarget ExNet Then
* * Net = TTarget - ExNet
* * While Net 0 And j < 100
* * * * Sheets("Sheet1").Range("G3") = 1
* * * * Sheets("Sheet1").Range("G4") = 0
* * * * j = j + 1
* * Wend
* * Else:
* * If ExNet TTarget Then
* * Net = Exnet - TTarget
* * While Net 0 And k < 100
* * * * Sheets("Sheet1").Range("G3") = 0
* * * * Sheets("Sheet1").Range("G4") = 1
* * * * k = k + 1
* * Wend
* * End If
i = i + 1
Wend
End If
End Sub

I placed the i,j, and k just to control the maximum times the loop occurs so
that it would not be indefinite.
I am getting errors with the 'Wend without While' compile error when the
above procedure is run.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Nested Do While Loops

If you indent your code, it makes it easier to line up your while/wend and
if/else/end if's.



While TTarget < 0 And i < 100
If TTarget ExNet Then
Net = TTarget - ExNet
While Net 0 And j < 100
Sheets("Sheet1").Range("G3") = 1
Sheets("Sheet1").Range("G4") = 0
j = j + 1
Wend
Else
If ExNet TTarget Then
Net = Exnet - TTarget
While Net 0 And k < 100
Sheets("Sheet1").Range("G3") = 0
Sheets("Sheet1").Range("G4") = 1
k = k + 1
Wend
End If
end if '<-- added
i = i + 1
Wend

Gum wrote:

I have been trying to get a nested Do While Loop and I need to find out where
I went wrong. The snippet of the procedure is as follows:

Sub control()
Dim Target1 As Integer
Dim Target2 As Integer
Dim TTarget As Integer
Dim Net As Integer
Dim ExNet As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer

BTarget = Sheets("Sheet1").Range("H3")
STarget = Sheets("Sheet1").Range("H4")
ExNet = Sheets("Sheet1").Range("N3")
TTarget = Target1 + Target2
While TTarget < 0 And i < 100
If TTarget ExNet Then
Net = TTarget - ExNet
While Net 0 And j < 100
Sheets("Sheet1").Range("G3") = 1
Sheets("Sheet1").Range("G4") = 0
j = j + 1
Wend
Else:
If ExNet TTarget Then
Net = Exnet - TTarget
While Net 0 And k < 100
Sheets("Sheet1").Range("G3") = 0
Sheets("Sheet1").Range("G4") = 1
k = k + 1
Wend
End If
i = i + 1
Wend
End If
End Sub

I placed the i,j, and k just to control the maximum times the loop occurs so
that it would not be indefinite.
I am getting errors with the 'Wend without While' compile error when the
above procedure is run.


--

Dave Peterson
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
Help with nested for loops [email protected] Excel Discussion (Misc queries) 5 May 2nd 07 05:30 PM
Help with nested for loops [email protected] Excel Worksheet Functions 5 May 2nd 07 05:30 PM
Many Nested loops naterator Excel Programming 4 June 19th 06 10:43 PM
nested loops jer Excel Programming 2 January 15th 06 09:09 PM
nested for loops and end for SandyR Excel Programming 3 October 6th 05 09:36 PM


All times are GMT +1. The time now is 12:43 PM.

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"