Extracting 1 or 2 Digits From The Start of A String

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,608
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a string ... 12 : 07-Jun-18 - 20-Jun-18

I am looking for a vba solution to extract the whole number that starts the string. In this case, 12. If this number was always two digits, using left(string,2) would be a simple solution, but would not work for single digit numbers (1-9). The preceding number will never be more than 2 digits.

Is anyone able to provide a solution for me?
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Yes ... thank you.
Exactly what I needed.

Out of curiosity, what function does the "--" provide?
 
Last edited:
Upvote 0
It forces the 12 to be a number rather than text. And also trims any excess spaces that might be left over from the LEFT function.

It's basically negative negative (###)...2 negatives is a positive.

You can also use "+0" or "*1" after you close out all of your functions...they all do the same thing...force a (possible) text to a number.
 
Upvote 0
I appreciate the explanation! It was difficult to phrase a Google search :-)
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,710
Members
452,994
Latest member
Janick

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