Concatenate Every Second Row for Certain Number of Rows

PostTIT

Board Regular
Joined
Aug 22, 2016
Messages
94
As my title suggests I'm wanting to concatenate data that is in a single column. (e.g. Column A:A)
But I only want to concatenate data in every second row (i.e. A1,A3,A5,etc...)
I have another cell (e.g. B1) that contains an inputted number by the user. I'm looking for this number to limit the amount of cells that are concatenated. (i.e. if "B1 = 6" then I want to concatenate "A1,A3,A5,A7,A9,A11" and if "B1 = 2" then concatenate "A1,A3")

I have tried a simple concatenate function and selected the cells that I want, but I'm looking to automate it using a function (not a macro as I find other users don't appreciate macro-enabled workbooks, therefore don't enable them, therefore miss out on the functions they provide).

I have tried concatenate(transpose) but with the same result as above.

I have tried the following formula:

Code:
=CONCATENATE((MOD(ROW(OFFSET($A$1,,,1+2*($B$1-1)))-ROW($A$1),2)=0)*OFFSET($A$1,,,1+2*($B$1-1)))

but it only outputted the final value, not all of them, which wasn't desired.

And then from that I've taken various edits of the OFFSET section of the formula and used with the CONCATENATE and TRANSPOSE functions and had no luck.
I feel like I'm fairly close, but just falling short every time. Any help would be greatly appreciated.
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Thanks Rory - white-listing the site was something I overlooked. I was confused as to why I had all the source/garbage code at the end of my posts.

And thanks Special, TEXTJOIN is more fluid than CONCATENATE is to use. I just need to figure out how to get it to only take the required number of cells into consideration.
I'll post an update when I have it.
 
Last edited:
Upvote 0
Stick an IF(MOD(ROW() ),2)= in the TEXTJOIN though that will make it an array formula (I think).

Something like

=TEXTJOIN(",",TRUE,IF(MOD(ROW(A1:Z1),2)=1,A1:Z1)

1 for odd numbered rows, 0 for even
 
Last edited:
Upvote 0
Right so thanks up till now, been very helpful.

However the thing that is missing now from the code is the ability for it to only join the text of a certain number of cells. Up till now you guys have helped get every second row in the dataset to be joined together, but if I am looking to only take the first 6 values, or the first 16 values (whatever the number, it will be based on the value in another cell) then I'm not quite sure what to do.
As I said initially I'd prefer to not have a macro do this, but a formula instead.

Any help please and thanks and thanks and please.
 
Upvote 0
My formula was way out ROW(A1:Z1) will only ever return 1. Looks like I meant ROW(A1:A1000)

Assuming the cell count is in B1
try this (dunno if it will work)

=TEXTJOIN(",",TRUE,IF((MOD(ROW(A1:A1000),2)=1)*(ROW(A1:Z1)<=B1*2+1),A1:A1000)
 
Upvote 0
Aye so the new formula works much like the previous iteration. The issue is with the IF statement where the formula does the test of MOD(ROW()) etc and then it outputs every second row between A1:A1000 in the TEXTJOIN. It's not able to limit it to only outputting the number of values specified in B1.
 
Upvote 0
I don't believe I've done it again!

Should be this

=TEXTJOIN(",",TRUE,IF((MOD(ROW(A1:A1000),2)=1)*(ROW(A1:A1000)<=B$1*2-1),A1:A1000)

The second part of the condition

(ROW(A1:A1000)<=B$1*2-1)

should limit the number of TEXTJOINs to only where the row number is less than B1*2-1, ie if B1 is 6 then odd numbered rows up to 6*2-1 = 11, ie 1, 3, 5, 7, 9, 11
 
Upvote 0
Unfortunately I think you have... From what I can work out all that happens is the if statement returns 'true' from that statement there:

MOD(ROW(A1:A1000),2)=1)*(ROW(A1:A1000)<=B$1*2-1)

and then it just takes all the values from A1:A1000 regardless. The values it is returning are not bound by any conditions.

ROW(A1:A1000) returns '1' as it is the first row. The MOD function with the '2' divisor returns '1' again. Which is, as in the formula, equal to '1'. Then you multiply '1' by Row(A1:A1000) which again is equal to 1.
B$1*2-1 is then fulfilled as true as long as the value in cell B1 is greater than '0'. Then it just takes all the data from A1:A1000.

Is there any way to have it so the formula does something like:

=TEXTJOIN(", ",TRUE,A1:A(B1))

Where it takes the value from B1 to replace the number of A1:A#?
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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