+ Reply to Thread
Results 1 to 4 of 4

IF statement for part of a number

  1. #1
    Registered User
    Join Date
    08-17-2016
    Location
    Florida, USA
    MS-Off Ver
    2010; 2013
    Posts
    9

    Question IF statement for part of a number

    Hello,

    I was wondering if there is a way to write an IF statement that looks at only one of the 4 digit numbers on another column and return a value based on them?

    For example:

    on A1 through A5 I have the following numbers: 9521, 7803, 6649, 4107, 5764.

    I want my IF Statement to look at the second number in each cell and return a specific value like this:
    If the second number is 5 then return value "Music"
    If the second number is 8 then return value "Movies"

    OR

    IF the second number value is between 1 and 3 then return value "Sports"
    IF the second number value is between 4 and 6 then return value "Music"

    Any help would be much appreciated.

    Thank you

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,144

    Re: IF statement for part of a number

    Do you mean 2nd DIGIT in each number?

  3. #3
    Registered User
    Join Date
    01-17-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, & 2010 Beta
    Posts
    78

    Re: IF statement for part of a number

    Following the specific example, with the precise values (of 2nd digit), here's one way: cell B1 could have: if(mid(A1,2,1)="5","Music",if(mid(A1,2,1)="8",... followed by whatever other values you wanted based on that 2nd digit. You could also make a vertical lookup table, with each value, in numerical order, in once column, and, alongside, the "music", "sports" values etc that you want to match to the numbers, then you would type into, say, B1:
    vlookup(mid(A1,2,1),2). In mid(A1,2,1), the 2 of this part of the formula is starting from the 2nd digit; the 1 after that means 1 digit only. In vlookup(mid(A1,2,1),2), the 1st column (the digits) are regarded as column 1, the digit is found, and - the 2 at the end of the formula - excel pulls up the matching value in the 2nd column of this table. Hope this makes some sense. Also check out vlookup for exact match, or between one value and another . . .

  4. #4
    Registered User
    Join Date
    08-17-2016
    Location
    Florida, USA
    MS-Off Ver
    2010; 2013
    Posts
    9

    Re: IF statement for part of a number

    lotusman,

    YOU THE MAN!!!!!!!

    Thank you so much! It worked perfectly!

+ 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] Enter part nrs consist....it display part number needed
    By ricklou in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2017, 07:16 AM
  2. sum only right part (number part) of the cells
    By jojo1 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-02-2015, 10:50 AM
  3. Help returning part number 1 time and adding up like part number QTY
    By SOLERSA in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-16-2014, 06:31 AM
  4. Nested IF statement validating part 1 but not part 2 of conditional
    By methuselah90 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-08-2014, 02:39 PM
  5. Multi part if statement
    By scruz9 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-22-2014, 07:52 AM
  6. Find Part number through Macro and output to associated part to certain cell
    By boylers75 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2012, 04:32 PM
  7. [SOLVED] IF Statement: What is the command for the "a number" part?
    By Flutie99 in forum Excel General
    Replies: 3
    Last Post: 05-27-2005, 06:05 PM

Tags for this Thread

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