Find number in string

bobkap

Active Member
Joined
Nov 22, 2009
Messages
313
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I have thousands of rows of data. In one column there's a string of both text and numbers. Some of the numbers are dates. The dates represent many different years, but I only want the dates for 2016 and 2017. I've tried using the IsStr function but I just could not get it to work.

Here my code lines for this:
banana = InStr((Cells(mirow, micol)), "2016" Or "2017")
If banana = 0 Then

I thought that if 2016 or 2017 was in the string that the result would be zero and in those cases I would do what I need to do with the cells that do and do not have 2016 or 2017 in them. BUT, I get not only zeros for my variable (banana) but weird numbers like 44 and 62 and I have no idea where they come from. Worse, I get hits on all my data, not just the ones that have 2016 or 2017 in the string. Here's an example of what one of my strings looks like:

PC Class 8:00AM-2:00 PM Jan 15th, 2016 (135 Elm St, Anycity, Anystate 34562

What would be a way to do this correctly please?

<tbody>
</tbody>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I have thousands of rows of data. In one column there's a string of both text and numbers. Some of the numbers are dates. The dates represent many different years, but I only want the dates for 2016 and 2017. I've tried using the IsStr function but I just could not get it to work.

Here my code lines for this:
banana = InStr((Cells(mirow, micol)), "2016" Or "2017")
If banana = 0 Then

I thought that if 2016 or 2017 was in the string that the result would be zero and in those cases I would do what I need to do with the cells that do and do not have 2016 or 2017 in them. BUT, I get not only zeros for my variable (banana) but weird numbers like 44 and 62 and I have no idea where they come from. Worse, I get hits on all my data, not just the ones that have 2016 or 2017 in the string. Here's an example of what one of my strings looks like:

PC Class 8:00AM-2:00 PM Jan 15th, 2016 (135 Elm St, Anycity, Anystate 34562

What would be a way to do this correctly please?

<tbody>
</tbody>
Is the year always located just in front of an opening parenthesis as shown in your single example?

As to your posted question, those "weird" numbers are the location within the text where the searched for text starts at. If you want the text itself, you would need to use the Mid function to get it.
 
Last edited:
Upvote 0
Unfortunately, no. Here's an example of another record:
ACC Course -- 9:00am to 4:00pm - February 6th, 2016

<tbody>
</tbody>
 
Upvote 0
Unfortunately, no. Here's an example of another record:
ACC Course -- 9:00am to 4:00pm - February 6th, 2016

<tbody>
</tbody>
When there is text after the date, is that text always encased in parentheses?
 
Upvote 0

Forum statistics

Threads
1,215,255
Messages
6,123,896
Members
449,132
Latest member
Rosie14

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