How to use IF, MID, AND in same formula?

Warbo

New Member
Joined
Jun 2, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I'm trying to write a formula(s) which split out some customer coding information so it can be cleanly moved - the idea is to combine all these into one formula so all information in one column (any suggestions on that too greatly appreciated)

So the rules are;
  • IF the customer number 5th letter is an A - it is a 'Statement' level code
    Successful formula I used - IF(MID(CELL,5,1)="A","STATEMENT","")

  • IF the customer number has 6 characters or more, it is a 'Delivery' level code
    Successful formula I used - IF(LEN(CELL)=>6,"DELIVERY","")

  • IF the customer number 5th letter is anything but A - it is an 'Invoice' level code - but I don't want it to consider text strings longer than 5 characters (as they Delivery level codes)
    Unsuccessful attempts - I've got as far as suggesting - IF(MID(CELL,5,1)<>"A","INVOICE","") - and a few attempts at trying to stick LEN, LEFT, with an AND statement, but all failed.
    Below image to illustrate that Invoice currently showing incorrectly against AA01B01

1685696287117.png


Many thanks in advance!

Dan
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
try:

Mr excel questions 39.xlsm
ABCD
1cust_noStatement (5 Letters end "A")Invoice (5 Letters Not "A")Delivery Point 6 Characters or more
2AA01ASTATEMENTSTATEMENTSTATEMENT
3AA01BDELIVERYDELIVERYDELIVERY
4AA01B01INVOICEINVOICEINVOICE
Sheet5
Cell Formulas
RangeFormula
B2:D4B2=IF(AND(LEN($A2)<=5,MID($A2,5,1)="A"),"STATEMENT", IF(AND(LEN($A2)>5,MID($A2,5,1)<>"A"),"INVOICE","DELIVERY"))
 
Upvote 0
try:

Mr excel questions 39.xlsm
ABCD
1cust_noStatement (5 Letters end "A")Invoice (5 Letters Not "A")Delivery Point 6 Characters or more
2AA01ASTATEMENTSTATEMENTSTATEMENT
3AA01BDELIVERYDELIVERYDELIVERY
4AA01B01INVOICEINVOICEINVOICE
Sheet5
Cell Formulas
RangeFormula
B2:D4B2=IF(AND(LEN($A2)<=5,MID($A2,5,1)="A"),"STATEMENT", IF(AND(LEN($A2)>5,MID($A2,5,1)<>"A"),"INVOICE","DELIVERY"))
This assumes anything else is delivery if that has other requirement you need to specify.
 
Upvote 0
Actually, this may be a better formula for you:

Mr excel questions 39.xlsm
ABCD
1cust_noStatement (5 Letters end "A")Invoice (5 Letters Not "A")Delivery Point 6 Characters or more
2AA01ASTATEMENT
3AA01BINVOICE
4AA01B01DELIVERY
Sheet5
Cell Formulas
RangeFormula
B2,D4,C3B2=IF(LEN($A2)>5,"DELIVERY", IF(AND(LEN($A2)<=5,MID($A2,5,1)="A"),"STATEMENT","INVOICE"))
 
Upvote 0
Actually, this may be a better formula for you:

Mr excel questions 39.xlsm
ABCD
1cust_noStatement (5 Letters end "A")Invoice (5 Letters Not "A")Delivery Point 6 Characters or more
2AA01ASTATEMENT
3AA01BINVOICE
4AA01B01DELIVERY
Sheet5
Cell Formulas
RangeFormula
B2,D4,C3B2=IF(LEN($A2)>5,"DELIVERY", IF(AND(LEN($A2)<=5,MID($A2,5,1)="A"),"STATEMENT","INVOICE"))

A more concise formula:

Excel Formula:
=IF(LEN($A2)>5,"DELIVERY",
IF(MID($A2,5,1)="A","STATEMENT","INVOICE"))
 
Upvote 0
Solution
A more concise formula:

Excel Formula:
=IF(LEN($A2)>5,"DELIVERY",
IF(MID($A2,5,1)="A","STATEMENT","INVOICE"))
Awoohaw - you sir, are a hero - that has worked an absolute treat - thank you! I was overcomplicating it all!
 
Upvote 0
@Warbo I'm happy you found a solution, thanks for the feedback.

And welcome to the Mr. Excel forum.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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