Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default not sure what's happening

IOamworking thru some learningmaterial and have the following code:

Sub Monthupdate()
m = Sheets("command").Cells(3, 1)
If (m = "January") Then
Sheets("Command").Cells(3, 1) = February
GoTo lab1:
End If

At this point the following message is displayed:-

<<...OLE_Obj...

It appears not to like the GoTo lab1:

I can't find any reference to lab1: before this point in the module, will
the label need defining? If so how is this done in VB?

If you have any suggestions they would be most appreciated.






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default not sure what's happening

Alex

lose the ":" at the end of lab1 before the End If.

You need the colon on the end of the actual label that you want to jump to

Sub Monthupdate()
m = Sheets("command").Cells(3, 1)
If (m = "January") Then
Sheets("Command").Cells(3, 1) = February
GoTo lab1
End If
'
'
'
lab1:


Regards

Trevor


"Alex H" wrote in message
...
IOamworking thru some learningmaterial and have the following code:

Sub Monthupdate()
m = Sheets("command").Cells(3, 1)
If (m = "January") Then
Sheets("Command").Cells(3, 1) = February
GoTo lab1:
End If

At this point the following message is displayed:-

<<...OLE_Obj...

It appears not to like the GoTo lab1:

I can't find any reference to lab1: before this point in the module, will
the label need defining? If so how is this done in VB?

If you have any suggestions they would be most appreciated.








  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default not sure what's happening

Labels are usually used in VBA as an escape exit in error conditions, and
usually placed near the end of a subroutine, where tidy-up code is entered.

To input a label, just enter

lab1:

on a line all by itself.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alex H" wrote in message
...
IOamworking thru some learningmaterial and have the following code:

Sub Monthupdate()
m = Sheets("command").Cells(3, 1)
If (m = "January") Then
Sheets("Command").Cells(3, 1) = February
GoTo lab1:
End If

At this point the following message is displayed:-

<<...OLE_Obj...

It appears not to like the GoTo lab1:

I can't find any reference to lab1: before this point in the module, will
the label need defining? If so how is this done in VB?

If you have any suggestions they would be most appreciated.








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default not sure what's happening

Alex,

You define a lable simply by typing in a name followed by a colon.

e.g.

Sub WithLabels()
StartProc: 'this is a label
End Sub

Looking at your code as it stands there is no label, so I have rewritten a
bit to show what the original author might have intended, and added a better
structure below avoiding the Goto. It's useful sometimes, but not a great
programming construct.

Sub Monthupdate()
m = Sheets("command").Cells(3, 1)
If (m = "January") Then
Sheets("Command").Cells(3, 1) = February
GoTo lab1:
End If
msgbox "The cell does not contain January"
lab1:
End Sub

The better version

Sub Monthupdate()
m = Sheets("command").Cells(3, 1)
If (m = "January") Then
Sheets("Command").Cells(3, 1) = February
else
msgbox "The cell does not contain January"
End If
End Sub

HTH,

Robin Hammond
www.enhanceddatasystems.com

"Alex H" wrote in message
...
IOamworking thru some learningmaterial and have the following code:

Sub Monthupdate()
m = Sheets("command").Cells(3, 1)
If (m = "January") Then
Sheets("Command").Cells(3, 1) = February
GoTo lab1:
End If

At this point the following message is displayed:-

<<...OLE_Obj...

It appears not to like the GoTo lab1:

I can't find any reference to lab1: before this point in the module, will
the label need defining? If so how is this done in VB?

If you have any suggestions they would be most appreciated.








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
Can anybody stop this happening please Pammi J New Users to Excel 4 February 18th 08 10:58 AM
Don't know what is happening.... B.Kundla Excel Discussion (Misc queries) 4 September 22nd 05 08:06 PM
Why this is happening springwinterfall Charts and Charting in Excel 4 January 9th 05 02:16 PM
Why is this happening? retcgr Excel Worksheet Functions 2 November 21st 04 11:20 PM
what's the Bug....tell me what's happening??? foamfollower Excel Programming 4 February 1st 04 04:04 PM


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