VBA - Extract Second word from Cell and Extract word before ","

eli_m

Board Regular
Joined
Jun 2, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am currently using:
Cells(ActiveCell.Row, "F").Value
Which is "John Doe" but I only want it to display the second word "Doe"

I also have

Cells(ActiveCell.Row, "A").Value
Which is "SMITH RODGERS, Jane" but I only want it to display the words that appear before the "," so it displays "SMITH RODGERS"

The full code is:
VBA Code:
Option Explicit
Sub CalendarInvite()
    Dim OutApp As Outlook.Application, Outmeet As Outlook.AppointmentItem

        Set OutApp = Outlook.Application
        Set Outmeet = OutApp.CreateItem(olAppointmentItem)
        
        With Outmeet
            .MeetingStatus = olMeeting
            .ReminderMinutesBeforeStart = 15
            .Subject = "Support: " & Cells(ActiveCell.Row, "F").Value & " Client: " & Cells(ActiveCell.Row, "A").Value & " - BOOKED"
            .Body = Cells(ActiveCell.Row, "J").Value
            .Location = Cells(ActiveCell.Row, "H").Value
            .Start = Cells(ActiveCell.Row, "B").Value
            .AllDayEvent = True
            .Display
        End With

    Set OutApp = Nothing
    Set Outmeet = Nothing
End Sub

Thanks in advance :)
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
From your description & then looking at your code I imagine that it is just the "Subject" line that you are talking about. If so, try this for that line

VBA Code:
.Subject = "Support: " & Split(Cells(ActiveCell.Row, "F").Value)(1) & " Client: " & Split(Cells(ActiveCell.Row, "A").Value, ",")(0) & " - BOOKED"
 
Upvote 0
Solution
From your description & then looking at your code I imagine that it is just the "Subject" line that you are talking about. If so, try this for that line

VBA Code:
.Subject = "Support: " & Split(Cells(ActiveCell.Row, "F").Value)(1) & " Client: " & Split(Cells(ActiveCell.Row, "A").Value, ",")(0) & " - BOOKED"
As soon as I got the email that "Peter_SSs replied" I knew it was going to be the right answer!
Thank you so much :)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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