string manipulation vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi

I wrote a code to ask user to enter first and last name and then the code will msgbox fullname. Now I want to improve the code. I want to msgbox the first letter for the first name then last name. So later I can msgbox the email address.

For example, if user enter John Smith

I want to msgbox --> JSmith

then later I will do

> your email address is JSmith@abc.com

Thank you very much.

Code:
Sub myname()
    Dim first As String
    Dim last As String
    Dim full As String
    first = InputBox("enter first name")
    last = InputBox("enter last name")
    full = first & "  " & last
    MsgBox "your full name is >> " & full
End Sub
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
Code:
    MsgBox "your full name is >> " & Left(first, 1) & last
 
Upvote 0
Thank you very much. That resolve the issue. Just one more question. What do you call Left() function here? Is it VBA function or Excel sheet function? Thank you once again
 
Upvote 0
What do you call Left() function here? Is it VBA function or Excel sheet function?
They just happen to be called the same thing and work the same way in both Excel and VBA.
So, it is BOTH an Excel and a VBA function.
 
Upvote 0
Further to Joe's comment, in general if a function is preceded with Application or WorksheetFunction then it's an xl function, otherwise it's VBA
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,205
Members
448,874
Latest member
Lancelots

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top