VBA Mid

This is a text and video example of how to write a VBA Mid function:

*************************************************************************************
Public Sub GetMiddleName()

      Dim strMiddleName As String

      strMiddleName = Range("A2")

      strMiddleName = Mid(strMiddleName, 9, 3)

      Range("C2") = strMiddleName

End Sub

'THE SECOND ARGUMENT OF THE VBA MID FUNCTION
'IS OPTIONAL
'SO YOU DON'T HAVE TO USE IT IF YOU DON'T WANT TO...
'THE FOLLOWING EXAMPLE EXCLUDES THE USE OF THE
'THIRD ARGUMENT...


Public Sub GetLast4()

      Dim strTempText As String

      strTempText = Range("A1")

      strTempText = Mid(strTempText, 7)

      Range("B1") = strTempText

End Sub

*************************************************************************************

Now watch how it's done...


That's all, I hope it helped! If not, feel free to email me at erik [at] vbahowto [dot] com

Are you struggling to learn VBA?

If your answer to the above question is yes, then I strongly recommend that you check out these VBA Crash Course videos