Extract Characters to the Right of the Right-Most Space in the String, in VBA

DougRobertson

Active Member
Joined
Sep 22, 2009
Messages
334
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm looking for VBA Code that will Extract all the Characters to the Right of the Right-Most Space in a String.

Where Cell "C6" contains the Text "From 8/1/2018 To 8/7/2018", I need to have the Variable iEndDate return the characters "8/7/2018".

Thank you in advance for any and all assistance!

(Using Excel 2016)

~ DWR
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hello,
One way would be to use " To " as a delimiter in the split function.
Code:
Option Explicit
Option Explicit
Sub splitstr()
 Dim str As String
    str = Split(Range("C6"), " To ")(1)
 MsgBox str
End Sub
 
Last edited:
Upvote 0
Bingo! Works to perfection!

Could you kindly explain what a Delimiter is and how it is used, and also what the "(1)" at the end of the formula does?

With much thanks!

~ DWR
 
Upvote 0
You can also use something like this
Code:
Sub RightPart()
  Dim iEndDate As String
  
  iEndDate = Mid(Range("C6").Value, InStrRev(Range("C6").Value, " ") + 1)
End Sub

On a side-note, I would definitely avoid using str as a variable in vba as that is one of vba's built-in function names.
 
Upvote 0
I just KNEW I could count on the Commonwealth to come through for me!

The Split function works best for my situation now, but I've also been looking for some help with the Mid function as well - thanks Guys!!

~ DWR
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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