View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Getting a message box program to run (Page 43 of 'Beginning Programming with VBA' by Duane Birnham)

Hi Simon,

Am Sun, 9 Nov 2014 07:06:08 -0800 (PST) schrieb
:

I seem to be running into difficulty running the following program in Excel.

I have made a Command Button and called it cmdBegin and given its caption as Begin in the properties window.

However upon pressing the button in the Excel Spreadsheet, it returns as an error (a yellow arrow) that the first line:

Private Sub cmd Begin_click()


there is a typo into the code.
Try:

Private Sub cmdBegin_Click()
Dim userName As String
Dim firstName As String
Dim lastName As String
Dim strLength As Integer
Dim spaceLoc As Integer
'----------------------------
'Collect user name, find the space between
'first and last names, and separate the names.
'------------------------------------------------
userName = InputBox("Enter your first and last name", "Name")
spaceLoc = InStr(1, userName, " ")
firstName = Left(userName, spaceLoc - 1)
'-----------------------------------------------
'Output to the worksheet
'-----------------------------------------------
Range("C3").Value = firstName
strLength = Len(firstName)
Range("C4").Value = strLength 'length of first name
strLength = Len(userName)
lastName = Mid(userName, spaceLoc + 1, strLength - spaceLoc)
Range("C5").Value = lastName
strLength = Len(lastName)
Range("C6").Value = strLength
Range("C7").Value = UCase(userName)
Range("C8").Value = LCase(userName)
Range("C9").Value = StrConv(userName, vbProperCase)
Range("C10").Value = StrReverse(userName)
Range("C11").Value = lastName & ", " & firstName
End Sub




Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional