Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Another Problem


This doesn't have anything to do with my other recent question but I'd
like to ask your help once again. If you don't know I'm new at the
whole VBA thing so if its obvious, please don't moan.
I've got a macro running that keeps displaying the same box (UserForm1)
again and again when you click the cross. When debugging it, it comes up
with this:

Code:
--------------------
Sub DealorNoDeal()
Do While Not Range("C30") = 1
If Range("D12") = 5 Then
UserForm1.Show
*End If*
Loop
Do While Not Range("C30") = 1
If Range("D12") = 8 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 11 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 14 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 17 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 20 Then
UserForm1.Show
End If
Loop
End Sub
--------------------

The first "End If" is highlighted yellow. What's wrong with the code
and is there a way you can guide me to to stop it doing itself again
and again?

And is it even possible to tell from that?


--
stupler
------------------------------------------------------------------------
stupler's Profile: http://www.excelforum.com/member.php...o&userid=32884
View this thread: http://www.excelforum.com/showthread...hreadid=527739

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Another Problem

It will continue looping unless you change the value in C30


Do While Not Range("C30") = 1
If Range("D12") = 5 Then
UserForm1.Show
End If
Loop

And consider using CASE statement to check values od D12 and put in a single
loop


Do While Not Range("C30") = 1
Select Case Range("d12")
Case 5, 8, 11, 14, 17, 20
UserForm1.Show
'<=== add code to change C30 condition .... what does C30 contain?
End Select

Loop
"stupler" wrote:


This doesn't have anything to do with my other recent question but I'd
like to ask your help once again. If you don't know I'm new at the
whole VBA thing so if its obvious, please don't moan.
I've got a macro running that keeps displaying the same box (UserForm1)
again and again when you click the cross. When debugging it, it comes up
with this:

Code:
--------------------
Sub DealorNoDeal()
Do While Not Range("C30") = 1
If Range("D12") = 5 Then
UserForm1.Show
*End If*
Loop
Do While Not Range("C30") = 1
If Range("D12") = 8 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 11 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 14 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 17 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 20 Then
UserForm1.Show
End If
Loop
End Sub
--------------------

The first "End If" is highlighted yellow. What's wrong with the code
and is there a way you can guide me to to stop it doing itself again
and again?

And is it even possible to tell from that?


--
stupler
------------------------------------------------------------------------
stupler's Profile: http://www.excelforum.com/member.php...o&userid=32884
View this thread: http://www.excelforum.com/showthread...hreadid=527739


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Another Problem

The easy part first: The reason the debug comes up with the indicated line
yellow shows simply that that is the next line of code waiting to be run.
That is not an error (unless you are getting an error message, which I don't
think you are).

Why does the box keep reappearing? It seems to me that this loop must be
"stuck":
Do While Not Range("C30") = 1
If Range("D12") = 5 Then
UserForm1.Show
*End If*
Loop
An "endless loop" is one of the most common programming problems. You are
looping as long as Range("C30")=1. There is nothing in your code that
changes the value of C30. Perhaps there is something in your UserForm's code
that is supposed to change it but if so I would suspect from the problem you
are having that it is not changing C30. The ONLY way out of the loop is for
C30 to be equal to 1, and this must also be cell C30 on the currently active
worksheet (unless you specify otherwise, that is what Range gives you).

So the first place to check is cell C30. When you stop the code, look at
your sheet and see what is in C30 on the current active worksheet. If it is
not 1, that is the problem. Then you need to find the place where your code
should be changing C30 and find out why it isn't working.
--
- K Dales


"stupler" wrote:


This doesn't have anything to do with my other recent question but I'd
like to ask your help once again. If you don't know I'm new at the
whole VBA thing so if its obvious, please don't moan.
I've got a macro running that keeps displaying the same box (UserForm1)
again and again when you click the cross. When debugging it, it comes up
with this:

Code:
--------------------
Sub DealorNoDeal()
Do While Not Range("C30") = 1
If Range("D12") = 5 Then
UserForm1.Show
*End If*
Loop
Do While Not Range("C30") = 1
If Range("D12") = 8 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 11 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 14 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 17 Then
UserForm1.Show
End If
Loop
Do While Not Range("C30") = 1
If Range("D12") = 20 Then
UserForm1.Show
End If
Loop
End Sub
--------------------

The first "End If" is highlighted yellow. What's wrong with the code
and is there a way you can guide me to to stop it doing itself again
and again?

And is it even possible to tell from that?


--
stupler
------------------------------------------------------------------------
stupler's Profile: http://www.excelforum.com/member.php...o&userid=32884
View this thread: http://www.excelforum.com/showthread...hreadid=527739


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Another Problem


Thanks everyone. You've been a huge help with this project that I'm new
at.
I was looking around for something similar to the "CODE" statement, but
couldn't find anything. Thanks for pointing it out.

I realise now that I've put the wrong number in the "Do While Not
Range("C30") = 1" bit. Thanks... again!

Seeing your comments, it all seems so obvious now! :D


--
stupler
------------------------------------------------------------------------
stupler's Profile: http://www.excelforum.com/member.php...o&userid=32884
View this thread: http://www.excelforum.com/showthread...hreadid=527739

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
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
problem with a conditional max problem Brian Cornejo Excel Discussion (Misc queries) 1 February 18th 05 06:25 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 06:35 AM.

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"