Concatenate range if number is between two numbers

erlendfs

New Member
Joined
Mar 11, 2022
Messages
5
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. Web
Hi,

Apologies in advance if this has been answered previously. I have tried searching the forum and google, but can't seem to find an answer to my issue.

I have two columns (E:F) with YYYYMM (ie. 202203 for this month) and Mmm-YY (ie Mar-22 for this month).

The data goes from January 2014 (201401 / Jan-14) to December 2027 (202712 / Des-27). At the end of each year, there is also a end of year row. The end of year row for 2027 is for instance 202713 in column E and EOY-27 in column F. All values in column E and F are created using formulas.

I would like to specify two YYYYMM values in two cells, and then a formula concatenates all YYYYMM and Mmm-YY values between these two values. For example, if I enter 202203 in the first cell, and 202201 in the second cell, the formula cell should evaluate to "202203-Mar-22-202202-Feb-22-202201-Jan-22", concatenating the values between the two ranges I specified.

Would this be possible using a formula? Alternatively using a macro?

Thanks for any help, and please let me know if you require any further details in solving this matter.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Data

202203​
Mar-22
202204​
Apr-22
202205​
May-22
202206​
Jun-22
202207​
Jul-22
202208​
Aug-22
202209​
Sep-22
202210​
Oct-22
202211​
Nov-22
202212​
Dec-22
202301​
Jan-23
202302​
Feb-23
202303​
Mar-23
202304​
Apr-23
202305​
May-23
202306​
Jun-23
202307​
Jul-23
202308​
Aug-23
202309​
Sep-23
202310​
Oct-23
202311​
Nov-23
KLM
Row3
202205​
202302​
202205-May-22-202206-Jun-22-202207-Jul-22-202208-Aug-22-202209-Sep-22-202210-Oct-22-202211-Nov-22-202212-Dec-22-202301-Jan-23-202302-Feb-23
In M3 ARRAY formula. Data range E2:F22
=TEXTJOIN("-",TRUE,IF(($E$2:$E$22>=K4)*($E$2:$E$22<=L4),$E$2:$F$22,""))

To enter ARRAY formula
Copy and paste the formula in cell
Press F2
Press Ctrl+Shift+Enter together
Excel covers the formula with {}.
 
Upvote 0
Hi,

Thank you very much for your solution, kvsrinivasamurthy!

I have tested the formula, and I have two follow up questions:
  • I can get it to work when I hardcode the Data-table. However, I would not get it to work if the Data-table is made up of formulas (which it is, and ideally it should be from an end user standpoint)
  • At the end of every year, there is a EOY row, like this

202202Feb-22
202201Jan-22
202113EOY-21
202112Dec-21
202111Nov-21
202110Oct-21
......

Is there any way to factor in the EOY-row? Currently it is not added to the cell where TEXTJOIN is applied.
 
Upvote 0
ABCDE
EOY-132022=C2&B$2 (evaluates to 202213)=$A$2&RIGHT(C2,2) (Evaluates to EOY-22)
Dec-122022=C3&B$3=$A$3&RIGHT(C3,2)

As mentioned, if I copy-paste and convert to values, it works, but does not work on the EOY. Therefore, I would like for it to also capture the EOY rows, in addition to accepting formulas in D and E (where the formula you originally provided is looking).

Thank you for your help, I feel stuck...
 
Upvote 0
Thank you for your input. The values in column D are added now, but the Dec-22 / EOY-22 values are not added to the textjoin formula cell. Do you know how to fix this please?
 
Upvote 0
My bad, I just retested and it seems to be working perfectly now. Thank you very much for your help!
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,016
Members
448,936
Latest member
almerpogi

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