VBA to return string between two spaces (first occurrence)

seaottr

Board Regular
Joined
Feb 10, 2010
Messages
60
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

I'm trying to use VBA to extract a string between two spaces.

Cell G3 = "Period: 2016-1-26 To 2016-12-26"

I want to return the first date in cell G3 (2016-1-26)

The problem is that the date isn't always the same length because the months and days don't include leading zeros.

Any help would be appreciated! Thanks in advance!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This would do that:

=TRIM(MID(SUBSTITUTE(G3," ",REPT(" ",LEN(G3))),LEN(G3),LEN(G3)))
 
Upvote 0
Thanks steve the fish, but I'm looking for VBA to do this :)
 
Last edited:
Upvote 0
Ah, I needed (2) instead of (1)! Thank you for your help!!!
 
Upvote 0

Forum statistics

Threads
1,216,372
Messages
6,130,223
Members
449,567
Latest member
ashsweety

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