Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compile Error: Loop without Do


I keep getting the following error "Compile Error: Loop without Do"

I am checking to see if A13 is empty if it is then enter the value in
txtorganization in cell A13 then end loop else increase cellposition by
1 and repeat the process...

any ideas how to solve this error??

Private Sub cmdInsert_Click()
Dim CellPosition, counter

counter = 1
CellPosition = a13
Do While counter <= 10
If [CellPosition].Value = " " Then
[CellPosition].Value = txtOrganization.Value
Exit Do
Else
CellPosition = a13 + 1
counter = counter + 1
Loop
End Sub


--
cedtech23
------------------------------------------------------------------------
cedtech23's Profile: http://www.excelforum.com/member.php...o&userid=31022
View this thread: http://www.excelforum.com/showthread...hreadid=507400

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Compile Error: Loop without Do

Need an "End If" statement before the "Loop" statement

"cedtech23" wrote:


I keep getting the following error "Compile Error: Loop without Do"

I am checking to see if A13 is empty if it is then enter the value in
txtorganization in cell A13 then end loop else increase cellposition by
1 and repeat the process...

any ideas how to solve this error??

Private Sub cmdInsert_Click()
Dim CellPosition, counter

counter = 1
CellPosition = a13
Do While counter <= 10
If [CellPosition].Value = " " Then
[CellPosition].Value = txtOrganization.Value
Exit Do
Else
CellPosition = a13 + 1
counter = counter + 1
Loop
End Sub


--
cedtech23
------------------------------------------------------------------------
cedtech23's Profile: http://www.excelforum.com/member.php...o&userid=31022
View this thread: http://www.excelforum.com/showthread...hreadid=507400


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Compile Error: Loop without Do


The problem is that your If...Else doesn't have the mandatory End If.

When the compiler encounters "Loop" before the expected EndIf, it causes the
error you describe, although the message is a bit misleading, it does point
in the correct general direction (something missing regarding the loop
itself or within the loop).

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"cedtech23" wrote
in message ...

I keep getting the following error "Compile Error: Loop without Do"

I am checking to see if A13 is empty if it is then enter the value in
txtorganization in cell A13 then end loop else increase cellposition by
1 and repeat the process...

any ideas how to solve this error??

Private Sub cmdInsert_Click()
Dim CellPosition, counter

counter = 1
CellPosition = a13
Do While counter <= 10
If [CellPosition].Value = " " Then
[CellPosition].Value = txtOrganization.Value
Exit Do
Else
CellPosition = a13 + 1
counter = counter + 1
Loop
End Sub


--
cedtech23
------------------------------------------------------------------------
cedtech23's Profile:
http://www.excelforum.com/member.php...o&userid=31022
View this thread: http://www.excelforum.com/showthread...hreadid=507400



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Compile Error: Loop without Do

This should run. I don't know if it does exactly what you want, but it will
at least compile and run. Always check you "if" and "end if" and indent your
code for readability.

Private Sub cmdInsert_Click()
Dim CellPosition As Range
Dim counter As Integer

counter = 1
Set CellPosition = Range("a13")
Do While counter <= 10
If CellPosition.Value = " " Then
CellPosition.Value = txtOrganization.Value
Exit Do
Else
Set CellPosition = CellPosition.Offset(1, 0)
counter = counter + 1
End If
Loop
End Sub
--
HTH...

Jim Thomlinson


"cedtech23" wrote:


I keep getting the following error "Compile Error: Loop without Do"

I am checking to see if A13 is empty if it is then enter the value in
txtorganization in cell A13 then end loop else increase cellposition by
1 and repeat the process...

any ideas how to solve this error??

Private Sub cmdInsert_Click()
Dim CellPosition, counter

counter = 1
CellPosition = a13
Do While counter <= 10
If [CellPosition].Value = " " Then
[CellPosition].Value = txtOrganization.Value
Exit Do
Else
CellPosition = a13 + 1
counter = counter + 1
Loop
End Sub


--
cedtech23
------------------------------------------------------------------------
cedtech23's Profile: http://www.excelforum.com/member.php...o&userid=31022
View this thread: http://www.excelforum.com/showthread...hreadid=507400


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compile Error: Loop without Do


does "Set CellPosition = CellPosition.Offset(1, 0)"

increase the cell by one??


--
cedtech23
------------------------------------------------------------------------
cedtech23's Profile: http://www.excelforum.com/member.php...o&userid=31022
View this thread: http://www.excelforum.com/showthread...hreadid=507400



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Compile Error: Loop without Do

Exactly... I made the variable into a range object. It is (kind of) similar
to the active cell. You need to use the set statement to move it around...
--
HTH...

Jim Thomlinson


"cedtech23" wrote:


does "Set CellPosition = CellPosition.Offset(1, 0)"

increase the cell by one??


--
cedtech23
------------------------------------------------------------------------
cedtech23's Profile: http://www.excelforum.com/member.php...o&userid=31022
View this thread: http://www.excelforum.com/showthread...hreadid=507400


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compile Error: Loop without Do


I placed my code in module1 and I get the following error “Run-Time
error: ‘424’ object required” when I click on debug it brings me to

“CellPosition.Value = txtOrganization.Value & " " & txtPosition.Value”

I don’t know what wrong because when I run it under Private Sub
cmdInsert_Click()
It works great. What am I missing??




Code:
--------------------
Private Sub cmdInsert_Click()

Info

End Sub

--------------------


In Module 1 I have


Code:
--------------------
Function Info()

Dim CellPosition As Range
Dim counter As Integer

counter = 1

Set CellPosition = Range("a13")
Do While counter <= 10
MsgBox CellPosition.Value
If CellPosition.Value = "" Then
CellPosition.Value = txtOrganization.Value & " " & txtPosition.Value
Exit Do
Else
Set CellPosition = CellPosition.Offset(1, 0)
counter = counter + 1
End If
Loop
End Function

--------------------


--
cedtech23
------------------------------------------------------------------------
cedtech23's Profile: http://www.excelforum.com/member.php...o&userid=31022
View this thread: http://www.excelforum.com/showthread...hreadid=507400

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compile Error: Loop without Do


Not a problem but then I am lost because I have several txtboxes that
have to test if the cell is blank and input data if so. Example

Test if A13 is blank if so input the vlaue in txtposition in that cel
(I did that with the code below)

Test if C13 is blank if so input the values in txtStartMonth an
txtStartYear in cell C13

Test if D13 is blank if so input the values in txtEndMonth an
txtEndYear in cell D13


I know how to do this for one cell but I am lost on how to bring i
call toegether for all my cell?? Some guidance would be helpful…


Code
-------------------


Private Sub cmdInsert_Click()

Dim CellPosition As Range
Dim counter As Integer

counter = 1

Set CellPosition = Range("a13")
Do While counter <= 10
MsgBox CellPosition.Value
If CellPosition.Value = "" Then
CellPosition.Value = txtOrganization.Value & " " & txtPosition.Value
Exit Do
Else
Set CellPosition = CellPosition.Offset(1, 0)
counter = counter + 1
End If
Loop

End Sub


-------------------

--
cedtech2
-----------------------------------------------------------------------
cedtech23's Profile: http://www.excelforum.com/member.php...fo&userid=3102
View this thread: http://www.excelforum.com/showthread.php?threadid=50740

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Compile Error: Loop without Do

cedtech23,

It seems to me you moved the code from the cmdInsert_Click method of a
control to a new module.

Assuming cmdInsert_Click is associated with UserForm1 simple preceed
with the control for example.

CellPosition.Value = UserForm1.txtOrganization.Value & " " &
UserForm1.txtPosition.Value





*** Sent via Developersdex http://www.developersdex.com ***
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 this error-Compile error: cant find project or library JackR Excel Discussion (Misc queries) 2 June 10th 06 09:09 PM
VBAProject name compile error, not defined at compile time Matthew Dodds Excel Programming 1 December 13th 05 07:17 PM
Compile error: Loop WIthout Do darin kelberlau Excel Programming 1 November 18th 05 05:48 PM
How do I get rid of "Compile error in hidden module" error message David Excel Discussion (Misc queries) 4 January 21st 05 11:39 PM


All times are GMT +1. The time now is 11:30 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"