Find if the number is present in string VBA

briguyUSA

New Member
Joined
Jun 10, 2021
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Does anyone know a method in VBA to find if the number is present within a string? For exmaple, I am searching through a column to find "284988" but it may be stated as "284988-25-1." I want the code to confirm that 284988 is indeed within the string albeit the extra bits. thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Let's say that you have "284988-25-1" in cell A1 and 284988 in cell B1.
To see if B1 is found in A1, you can do this:
Excel Formula:
=IF(ISNUMBER(SEARCH(B1,A1)),"Found","Not Found")
 
Upvote 0
You haven't given us much detail, but you can do it like
VBA Code:
   For Each cl In Range("G2", Range("G" & Rows.Count).End(xlUp))
      If InStr(1, cl.Value, "284988") > 0 Then cl.Offset(, 1).Value = "Yes"
   Next cl
 
Upvote 0
Whoops. Sorry. I overlooked the VBA part.
But looks like Fluff's got you covered!
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,026
Members
449,061
Latest member
TheRealJoaquin

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