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


Why am I having problems with the following code below.....

Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!

Any Ideas????



For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRan ge,
1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down


If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else

Next iRange 'WONT WORK, ERROR = "Next Without For"

MsgBox "You are not an authorised Administrator of the System",
vbInformation, "Information" 'and display message

End If


--
gillettos
------------------------------------------------------------------------
gillettos's Profile: http://www.thecodecage.com/forumz/member.php?u=2090
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: ---
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Next Without For

'--
strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(IRan ge, 1).Text
For IRange = 1 To iRowNo
If strUsrID = iUsrId Then
IsThere = True
Exit For
End If
Next 'IRange

If IsThere Then
Unload FrmNavigation
FrmAdmin.Show
Else
MsgBox "You are not an authorized Administrator of the System", _
vbInformation, "Information"
End If
--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/ExtrasForXL




"gillettos"

wrote in message
...
Why am I having problems with the following code below.....
Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!
Any Ideas????

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRan ge,
1).Text
For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
If strUsrID = iUsrId Then
Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation
Else
Next iRange 'WONT WORK, ERROR = "Next Without For"
MsgBox "You are not an authorised Administrator of the System",
vbInformation, "Information" 'and display message
End If
--
gillettos

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default Next Without For

On Wed, 21 Jul 2010 10:20:21 +0100, gillettos
wrote:


Why am I having problems with the following code below.....

Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!

Any Ideas????



For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRan ge,
1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

If strUsrID = iUsrId Then
Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation
End If

If strUsrID < iUsrId Then
MsgBox "You are not an authorised Administrator of the
System", vbInformation, "Information" 'and display message
End If

Next iRange
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default Next Without For

On Wed, 21 Jul 2010 06:37:16 -0400, Ron Rosenfeld
wrote:

On Wed, 21 Jul 2010 10:20:21 +0100, gillettos
wrote:


Why am I having problems with the following code below.....

Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!

Any Ideas????



For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRan ge,
1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

If strUsrID = iUsrId Then
Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation
End If

If strUsrID < iUsrId Then
MsgBox "You are not an authorised Administrator of the
System", vbInformation, "Information" 'and display message
End If

Next iRange


Just a suggestion if it fits in with what you want to do:

Add an Exit For to the second "If" clause, so you don't cycle through
the msgbox for each row.

......
If strUsrID < iUsrId Then
MsgBox "You are not an authorised Administrator of the
System", vbInformation, "Information" 'and display message
Exit For
End If
.....
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Next Without For


gillettos;739962 Wrote:

Why am I having problems with the following code below.....

Basically I get the "Next witout For" Compile error when running the
code. Understand what its sayin, but by placing the "Next iRange"
outside the If statement kinda defeats the object of what I want to
do....!

Any Ideas????





VBA Code:
--------------------



For iRange = 1 To iRowNo 'set a loop of rows to cyclce down

strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(iRan ge, 1).Text

For iRange = 1 To iRowNo 'set a loop of rows to cyclce down


If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else

Next iRange 'WONT WORK, ERROR = "Next Without For"

MsgBox "You are not an authorised Administrator of the System", vbInformation, "Information" 'and display message

End If

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




You have repeated this line

VBA Code:
--------------------


For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
--------------------


but you only have one NEXT so either delete the line or add a NEXT.


--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?u=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: ---


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Next Without For


Simon Lloyd;739963 Wrote:

You have repeated this line

VBA Code:
--------------------


For iRange = 1 To iRowNo 'set a loop of rows to cyclce down
--------------------


but you only have one NEXT so either delete the line or add a NEXT.



Please ignore that line of code, it should be commented out, I was just
playing in trying to resolve the problem.

I have actually sorted it in a fashion, by moving the msg box after the
next line, it works, only prob being the msgbox comes up everytime, ie,
even with logit users.

I know this is something stupidly obviously but I'm just totally
drained at the mo!!


--
gillettos
------------------------------------------------------------------------
gillettos's Profile: http://www.thecodecage.com/forumz/member.php?u=2090
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: ---
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Next Without For


gillettos;739964 Wrote:

Please ignore that line of code, it should be commented out, I was just
playing in trying to resolve the problem.

I have actually sorted it in a fashion, by moving the msg box after the
next line, it works, only prob being the msgbox comes up everytime, ie,
even with logit users.

I know this is something stupidly obviously but I'm just totally
drained at the mo!!


This is how it should look:

VBA Code:
--------------------


strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(IRan ge, 1).Text

For IRange = 1 To iRowNo 'set a loop of rows to cyclce down


If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else

MsgBox "You are not an authorised Administrator of the System", vbInformation, "Information" 'and display message
End If
Next IRange
--------------------


if it does not perform as expected then look at what you are trying to
capture and check you're getting what you expect try this code instead:

VBA Code:
--------------------


strUsrID = ActiveWorkbook.Sheets("Administrators").Cells(IRan ge, 1).Text
MsgBox strUsrID & " beginning of code"
MsgBox iUsrId & " beginning of code"

For IRange = 1 To iRowNo 'set a loop of rows to cyclce down

If strUsrID = iUsrId Then

Load FrmAdmin
FrmAdmin.Show
Unload FrmNavigation

Else
MsgBox strUsrID & " value when if condition failed"
MsgBox iUsrId & " value when if condition failed"
MsgBox "You are not an authorised Administrator of the System", vbInformation, "Information" 'and display message
End If
Next IRange
--------------------


--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?u=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207715

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: ---
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



All times are GMT +1. The time now is 12:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"