Extracting 1 or 2 Digits From The Start of A String

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,223,703
Messages
6,173,977
Members
452,540
Latest member
haasro02

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