Creating a dynamic formula to exceed words from a file name

bearcub

Well-known Member
Joined
May 18, 2005
Messages
701
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I have the following formula that I use to extract either "Accruals" or "Payments" from the current file name

Excel Formula:
MID(CELL("filename",'Comm_Sept 22 US Summary'!$A$1),
FIND("[",CELL("filename",'Comm_Sept 22 US Summary'!$A$1))+60,
FIND("]",CELL("filename",'Comm_Sept 22 US Summary'!$A$1))-
FIND("[",CELL("filename",'Comm_Sept 22 US Summary'!$A$1))-65)
Excel Formula:

The following month I will change the file name & the text length might change due to the current month (e.g. March - April, April - May, May - June , August - September, September - October, etc).

In other words, the file size will either expand or contract due to the processing month.

The current file name I am using is called "Compensation Summary US Oct 22 - September 22 Commission Payments".

Next month, I will change to the name to "Compensation Summary US Nov 22 - October 22 Commission Payments".

September has 9 letters and October contains 8.

When I process November for October (commissions are always processed the following month), I will have to change the 60 to 61 and 65 to 64 in the formula to be able to extract "Payments" from the File Name since October has 1 less letter than September

Is there a way of making the formula I am using dynamic so I won't have to manually update the formula each month? I am working that I might just have to settle for 3 letter month as opposed to using the full month name.

Thank you for your help in advance.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Bearcub,

Here are two approaches to handle that:

Compensation Summary US Oct 22 - September 22 Commission Payments.xlsx
ABCD
1Max characters in target strings8
2Payments8
3Accruals8
4Luckily 8 characters all the way
5C:\MrExcel\[Compensation Summary US Oct 22 - September 22 Commission Payments.xlsx]Sheet1Payments
6C:\MrExcel\[Compensation Summary US Oct 22 - June 22 Commission Accruals.xlsx]Sheet1Accruals
7
8A different approachString's length
9Payments8
10Accruals8
11Overpayments12
12Biaccruals10
13
14Target String's startWhat is?
15C:\MrExcel\[Compensation Summary US Oct 22 - September 22 Commission Payments.xlsx]Sheet170Payments
16C:\MrExcel\[Compensation Summary US Oct 22 - September 22 Commission Accruals.xlsx]Sheet270Accruals
17C:\MrExcel\[Compensation Summary US Oct 22 - June 22 Commission Overpayments.xlsx]Sheet165Overpayments
18C:\MrExcel\[Compensation Summary US Oct 22 - June 22 Commission Biaccruals.xlsx]Sheet265Biaccruals
Sheet1
Cell Formulas
RangeFormula
C1C1=MAX(C2:C3)
C9:C12,C2:C3C2=LEN(B2)
C5:C6C5=MID($B5,FIND(".",$B5)-$C$1,$C$1)
C15:C18C15=FIND(B9,B15)
D15:D18D15=MID(B15,C15,C9)


Cheers!

G
 
Upvote 0
... and the second approach using a lookup table to select the right length whatever string appears in the name of the file.

Compensation Summary US Oct 22 - September 22 Commission Payments.xlsx
ABCD
1Max characters in target strings8
2Payments8
3Accruals8
4Luckily 8 characters all the way
5C:\MrExcel\[Compensation Summary US Oct 22 - September 22 Commission Payments.xlsx]Sheet1Payments
6C:\MrExcel\[Compensation Summary US Oct 22 - June 22 Commission Accruals.xlsx]Sheet1Accruals
7
8A different approach with a lookup table to adapt for changes)String's lengthTarget String's start
9Payments870
10Accruals870
11Overpayments1265
12Biaccruals1065
13
14Len
15C:\MrExcel\[Compensation Summary US Oct 22 - September 22 Commission Payments.xlsx]Sheet189
16C:\MrExcel\[Compensation Summary US Oct 22 - September 22 Commission Accruals.xlsx]Sheet289
17C:\MrExcel\[Compensation Summary US Oct 22 - June 22 Commission Overpayments.xlsx]Sheet188
18C:\MrExcel\[Compensation Summary US Oct 22 - June 22 Commission Biaccruals.xlsx]Sheet286
19
20What is?
21C:\MrExcel\[Compensation Summary US Oct 22 - June 22 Commission Overpayments.xlsx]Sheet1- 
22- 
23651.353846154
24- 
25
26Overpayments12
27
Sheet1 (3)
Cell Formulas
RangeFormula
C1C1=MAX(C2:C3)
C15:C18,C9:C12,C2:C3C2=LEN(B2)
C5:C6C5=MID($B5,FIND(".",$B5)-$C$1,$C$1)
D9:D12D9=FIND(B9,B15)
B21B21=B17
C21:C24C21=IFERROR(FIND(B9,$B$21),"-")
D21:D24D21=IFERROR((C15/C21),"")
C26C26=MID(B21,MAX(C21:C24),INDEX(C9:C12,MATCH(MAX($D$21:$D$24),$D$21:$D$24,0),1))
D26D26=INDEX(C9:C12,MATCH(MAX(D21:D24),D21:D24,0),1)
 
Upvote 0
Solution
Thank for your the process and the formulas.

I will use this approach going forward.

Thank you for spending the time to provide me with this solution because it looks like this took a lot of effort on your side to make arrive at this solution.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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