ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Do while loop (https://www.excelbanter.com/excel-programming/356746-do-while-loop.html)

Vanna

Do while loop
 
I need to create a loop to test if the value "56A" exist. It should loop
until C<25. If "56A" exists, then call a function. If c reaches 25 and
"56A" does not exist, then call a different function.

I had this code created. It seems like both the happy and sad functions are
performed when "56A" is found.

What's a better method to put this code?

c = 10
Do While sValue < "56A" or c<25

If sValue = "56A" Then
call happy
Else
c = c + 1
End If

Loop
call sad

Myles[_56_]

Do while loop
 

Hi Vanna,

Not surprising. After "56A" is found and "Happy" called, the loop i
exited only to call "Sad" again. To avoid calling "Sad" after "Happy"
adjust your code thus:

c = 10
Do While sValue < "56A" or c<25

If sValue = "56A" Then
call happy
EXIT SUB ===== INSERTE
Else
c = c + 1
End If

Loop
call sad




Myle

--
Myle
-----------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...fo&userid=2874
View this thread: http://www.excelforum.com/showthread.php?threadid=52508


Vanna

Do while loop
 
Hi Myles,
thank you very much for answering to my post.
I tried your solution and it worked for me partially. Now I'm getting
information populated in my "Happy" worksheet, but I'm also getting
information populated for my "Sad" worksheet.

Perhaps I didn't explain my situation in enough detailed.

I have a do loop inside a do loop. Say, List of A to Z records
Inside each record, I need to extract field inforamation and populate them
into the "happy" or "Sad" spreadsheet. I don't know where I should put my
"SAD" function so that it only runs either "Happy" or "SAD". Now, I'm
getting results on both spreadsheets

bError = False
x = 15
intNumberOfTrades = 7
i = 8

Do Until bError = True

If sValue = " " Then
Exit Do
End If



'---------------------------------------------------------------------
' Check if Further Benneficiary exists (row 56A on Audsum
Mnemonic)
' if true, call HAPPY

'---------------------------------------------------------------------


c = 9
Do While (sValue < "56A" Or c < 25)

sValue = Trim$(sValue)

If sValue = "56A" Then
Call HAPPY
Exit Do
Else
c = c + 1
End If


Loop

Call SAD


i = i + 1
intNumberOfTrades = intNumberOfTrades + 1


If x < 37 Then
x = x + 2

ElseIf x = 37 Then
'go to next screen
x = 15
End If

rc = MB_CopyPSToString(gPSid, 40, 2, 5, sMessage) '

If sMessage = "I9001" Or sMessage = "E8001" Then
bError = True
End If

Loop


All times are GMT +1. The time now is 10:19 AM.

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