View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
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.