+ Reply to Thread
Results 1 to 10 of 10

Check to see if any characters are the same.

  1. #1
    Registered User
    Join Date
    10-10-2017
    Location
    UK
    MS-Off Ver
    365
    Posts
    28

    Check to see if any characters are the same.

    Hi all,

    I would like an if function which would check to see if a string of numbers has any of the same characters as a variable.

    I.e. if my variable is 35, I'd like the if function to be true if the cell contains either 3 or 5.

    Thanks

  2. #2
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Check to see if any characters are the same.

    If your cells just contain 3 or 5
    =ISNUMBER(SEARCH(a1,a2,1))
    =ISNUMBER(SEARCH(cell with 3 or 5,cell with 35,1))

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check to see if any characters are the same.

    Please Login or Register  to view this content.

    Tested using S = abcd3hgg, V = 35.

    This will support any length of string or variable.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    10-10-2017
    Location
    UK
    MS-Off Ver
    365
    Posts
    28

    Re: Check to see if any characters are the same.

    Quote Originally Posted by davsth View Post
    If your cells just contain 3 or 5
    =ISNUMBER(SEARCH(a1,a2,1))
    =ISNUMBER(SEARCH(cell with 3 or 5,cell with 35,1))
    Thanks for the help

    The variable could be 235.

    If the cell has a 2, a 3 or a 5 anywhere in it than I need a value of true. Would this work?

  5. #5
    Registered User
    Join Date
    10-10-2017
    Location
    UK
    MS-Off Ver
    365
    Posts
    28

    Re: Check to see if any characters are the same.

    Quote Originally Posted by mehmetcik View Post
    Please Login or Register  to view this content.

    Tested using S = abcd3hgg, V = 35.

    This will support any length of string or variable.
    I'll try this now, thank you.

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,420

    Re: Check to see if any characters are the same.

    Here is a UDF (user defined function) that will do what you asked for...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-10-2017
    Location
    UK
    MS-Off Ver
    365
    Posts
    28

    Re: Check to see if any characters are the same.

    Quote Originally Posted by Rick Rothstein View Post
    Here is a UDF (user defined function) that will do what you asked for...
    Please Login or Register  to view this content.
    Thanks, though i still don't properly know how to use a function in a sub

  8. #8
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,420

    Re: Check to see if any characters are the same.

    I just thought of a way to make the function you want without using any loops...
    Please Login or Register  to view this content.
    Note: This function assumes the first argument is a number composed of all digits only.
    Last edited by Rick Rothstein; 09-17-2020 at 11:33 AM.

  9. #9
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,420

    Re: Check to see if any characters are the same.

    Quote Originally Posted by DouglasWicker View Post
    Thanks, though i still don't properly know how to use a function in a sub
    You would use any of the posted functions the same way you would use a built-in function... pass the arguments into it and do something with the result. For example...

    If NumInNum(123456, 35) Then
    ....
    End If

    or...

    MsgBox NumInNum(123456, 35)

    or...

    SomeBooleanVariable = NumInNum(123456, 35)

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check to see if any characters are the same.

    Save the function in a Macro Module.

    Type something like abcde4h3fgg in A1
    Type =VarF(A1, 235) in any other cell.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] check first 3 characters to last 4
    By makinmomb in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-26-2017, 03:16 AM
  2. check for characters and replace
    By saravanan1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2015, 03:30 AM
  3. [SOLVED] Count & check characters in row
    By IHCCasper in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2012, 10:57 AM
  4. [SOLVED] Check ImputBox Characters
    By Pulsus in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-10-2012, 11:07 AM
  5. Check a column for certain characters
    By Rinocerinho in forum Excel General
    Replies: 12
    Last Post: 02-08-2010, 02:44 AM
  6. check for illegal characters
    By damteity in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2008, 04:06 PM
  7. Check for Alpha characters
    By TimE in forum Excel General
    Replies: 4
    Last Post: 11-09-2005, 08:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1