Excel Object Model VBA - Part2 - MsgBox and Functions

Public Sub msgBoxTester()
'Define Varibales
Dim sName As String

' Prompt the user for input data
sName = InputBox("Please enter your name", "Test", "First Name")

' Ask the user if the information is correct?
'MsgBox "Are you sure this information is correct", vbQuestion + vbYesNoCancel + vbDefaultButton2, Verification = vbIgnore

MsgBox Left(sName, 3)
MsgBox Right(sName, 3)
MsgBox Mid(sName, 3, 5)
MsgBox Mid(sName, 3)

'InStr - In string - search
' VB - We count 0,1,2,3,4,5
' InStr - Value > 0 - position starts from 1
MsgBox InStr(1, sName, " ")

' Get First Name
MsgBox Left(InStr(1, sName, " "))

' Get Last Name
MsgBox Right(InStr(1, sName, " "))

' Gives this with spaces
MsgBox Mid(InStr(1, sName, " "))

' Trim Function
' Ltrim, Trim, RTrim
MsgBox Mid(Trim(InStr(1, sName, " ")))



End Sub

Analytics