Find number in string

bobkap

Active Member
Joined
Nov 22, 2009
Messages
323
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
[TABLE="width: 445"]
<tbody>[TR]
[TD="width: 445"]
What would be a way to do this correctly please?[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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
[TABLE="width: 445"]
<tbody>[TR]
[TD="width: 445"]
What would be a way to do this correctly please?[/TD]
[/TR]
</tbody>[/TABLE]
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:
[TABLE="width: 445"]
<tbody>[TR]
[TD="width: 445"]ACC Course -- 9:00am to 4:00pm - February 6th, 2016[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Unfortunately, no. Here's an example of another record:
[TABLE="width: 445"]
<tbody>[TR]
[TD="width: 445"]ACC Course -- 9:00am to 4:00pm - February 6th, 2016[/TD]
[/TR]
</tbody>[/TABLE]
When there is text after the date, is that text always encased in parentheses?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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