Variable number of columns to concatenate dynamically

pcsrvc

New Member
Joined
Jun 28, 2022
Messages
9
Office Version
  1. 365
Platform
  1. MacOS
Hi all!

As you can see I am very new to the message board and have been studying Excel and VBA very hard and hopefully one day I will be able to pay it forward and help people out here as well. While I get my skills up to the task I would love it if you could help me out with something that might be very simple for you but I have not been successful finding a solution after researching for at least a week.

This is my problem:

I have a varying number of columns containing strings of text. I need to concatenate the middle strings. The position where the joining starts varies based on the value of a cell on the same row. First and last strings are ignored.

Example: Columns D - H, row 2: Sir John Wick Warhurst Taylor

I need to ignore "Sir" and "John", concatenate "Wick Warhurst", ignore Taylor. After that I will have to copy John, Wick Warhurst and Taylor to 3 different columns on the same row.

The number of strings can be anything up to 10. The result of the concatenation will always be 3 separate strings no matter how many strings are in the middle.

Can anyone please help? I will certainly study any codes you can come up with to learn how you did it and improve my skills.

Thank you in advance, you all are the best!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Post some rows of data as an example using below link.
 
Upvote 0
Does the below help?

The Starting row column states what column the concatenation should start. Particle Test column states whether the string on column 4 should be added to the last string resulting the same as the first row of date on the table below.

Starting rowParticle Test123456FIRSTMIDDLELAST
2TRUEAvenidaJuscelinoKubitschekDeOliveiraJuscelinoKubitschekDe Oliveira
2TRUERodoviaJuscelinoKubitschekDeOliveira/br-364/br-163
2FALSEEstradaFranciscoDaCruzNunes
2TRUEAvenidaAyrtonSennaDaSilva
2TRUERuaCláudioManoelDaCosta
2FALSERodoviaErnâniDoAmaralPeixoto/rj-106
2TRUEAvenidaRaimundoPereiraDeMagalhães
2TRUERodoviaJuscelinoKubitschekDeOliveira/br-364
2TRUERuaJuscelinoKubitschekDeOliveira
3TRUERuaFreiHenriqueDeCoimbra
3TRUEAvenidaGalOsórioDePaiva
2TRUEAvenidaJoãoNavesDeÁvila
2TRUERuaPeroVazDeCaminha
2FALSERuaFernãoDiasPaesLeme
2TRUEAvenidaEduardoFróesDaMota
4FALSERodoviaAnelRodoviárioCelsoMelloAzevedo/br-262
2FALSEAvenidaJoséBentoRibeiroDantas
2FALSERuaCatuloDaPaixãoCearense
2FALSEAvenidaJoaquimDaCostaLima
2TRUEAvenidaBentoMunhozDaRochaNeto
2TRUEAvenidaArmandoSallesDeOliveira
2TRUEAvenidaAmadorBuenoDaVeiga
2FALSERuaTancredoDeAlmeidaNeves
2FALSEAvenidaDorivalCândidoLuzDeOliveira
2TRUERodoviaFelicianoSallesDaCunha/sp-310
3FALSEAvenidaJuízMarçoTúlioIsaac
2TRUEAvenidaOsvaldoJoséDoAmaral
2FALSERodoviaEuclídesDeOliveiraFigueiredo/sp-563
2TRUERuaJoséLinsDoRego
2TRUEAvenidaJoséPontesDeAlmeida
2TRUERuaJoãoPereiraDaSilva
2TRUEAvenidaAdhemarPereiraDeBarros
2TRUERuaIsmaelJoséDoNascimento
2TRUERuaBartolomeuBuenoDaSilva
3FALSERodoviaJoãoDaSilvaMaia/br-135
2TRUERuaAyrtonSennaDaSilva
3FALSEAvenidaPastorMartinLutherKingJr
2TRUEAvenidaMozartPinheiroDeLucena
2FALSEAvenidaGetúlioDornelesVargas-N
2TRUEAvenidaMárioHomemDeMelo
2FALSEAvenidaDanielDeTouche
3FALSEAvenidaPastorMartinLutherKingJúnior
2TRUERuaCaetanoMunhozDaRocha
2FALSERodoviaRaphaelDeAlmeidaMagalhaes/br-493/rj-109
 
Upvote 0
Also, I have a tab that specifies whether the contents of row 1 and 2 should be ignored in order to come up with the starting row value if that helps.
 
Upvote 0
I do not understand fully what you want to achieve but see and let me know what changes you need in this

Book1
ABCDEFGHIJKLMNOP
1Starting rowParticle Test123456FIRSTMIDDLELASTFIRSTMIDDLELAST
22TRUEAvenidaJuscelinoKubitschekDeOliveiraJuscelinoKubitschekDe OliveiraJuscelinoKubitschekDe Oliveira
32TRUERodoviaJuscelinoKubitschekDeOliveira/br-364/br-163JuscelinoKubitschekDe Oliveira/br-364/br-163
42FALSEEstradaFranciscoDaCruzNunesFranciscoDaNunes
52TRUEAvenidaAyrtonSennaDaSilvaAyrtonSennaDa Silva
62TRUERuaCláudioManoelDaCostaCláudioManoelDa Costa
72FALSERodoviaErnâniDoAmaralPeixoto/rj-106ErnâniDoPeixoto/rj-106
82TRUEAvenidaRaimundoPereiraDeMagalhãesRaimundoPereiraDe Magalhães
92TRUERodoviaJuscelinoKubitschekDeOliveira/br-364JuscelinoKubitschekDe Oliveira/br-364
102TRUERuaJuscelinoKubitschekDeOliveiraJuscelinoKubitschekDe Oliveira
113TRUERuaFreiHenriqueDeCoimbraHenriqueDeDe Coimbra
123TRUEAvenidaGalOsórioDePaivaOsórioDeDe Paiva
132TRUEAvenidaJoãoNavesDeÁvilaJoãoNavesDe Ávila
142TRUERuaPeroVazDeCaminhaPeroVazDe Caminha
152FALSERuaFernãoDiasPaesLemeFernãoDiasLeme
162TRUEAvenidaEduardoFróesDaMotaEduardoFróesDa Mota
174FALSERodoviaAnelRodoviárioCelsoMelloAzevedo/br-262CelsoMelloMello
182FALSEAvenidaJoséBentoRibeiroDantasJoséBentoDantas
192FALSERuaCatuloDaPaixãoCearenseCatuloDaCearense
202FALSEAvenidaJoaquimDaCostaLimaJoaquimDaLima
212TRUEAvenidaBentoMunhozDaRochaNetoBentoMunhozDa Rocha
222TRUEAvenidaArmandoSallesDeOliveiraArmandoSallesDe Oliveira
232TRUEAvenidaAmadorBuenoDaVeigaAmadorBuenoDa Veiga
242FALSERuaTancredoDeAlmeidaNevesTancredoDeNeves
252FALSEAvenidaDorivalCândidoLuzDeOliveiraDorivalCândidoDe
262TRUERodoviaFelicianoSallesDaCunha/sp-310FelicianoSallesDa Cunha/sp-310
273FALSEAvenidaJuízMarçoTúlioIsaacMarçoTúlioIsaac
282TRUEAvenidaOsvaldoJoséDoAmaralOsvaldoJoséDo Amaral
292FALSERodoviaEuclídesDeOliveiraFigueiredo/sp-563EuclídesDeFigueiredo/sp-563
302TRUERuaJoséLinsDoRegoJoséLinsDo Rego
312TRUEAvenidaJoséPontesDeAlmeidaJoséPontesDe Almeida
322TRUERuaJoãoPereiraDaSilvaJoãoPereiraDa Silva
332TRUEAvenidaAdhemarPereiraDeBarrosAdhemarPereiraDe Barros
342TRUERuaIsmaelJoséDoNascimentoIsmaelJoséDo Nascimento
352TRUERuaBartolomeuBuenoDaSilvaBartolomeuBuenoDa Silva
363FALSERodoviaJoãoDaSilvaMaia/br-135DaSilvaMaia/br-135
372TRUERuaAyrtonSennaDaSilvaAyrtonSennaDa Silva
383FALSEAvenidaPastorMartinLutherKingJrMartinLutherKing
392TRUEAvenidaMozartPinheiroDeLucenaMozartPinheiroDe Lucena
402FALSEAvenidaGetúlioDornelesVargas-NGetúlioDorneles-
412TRUEAvenidaMárioHomemDeMeloMárioHomemDe Melo
422FALSEAvenidaDanielDeToucheDanielDeTouche
433FALSEAvenidaPastorMartinLutherKingJúniorMartinLutherKing
442TRUERuaCaetanoMunhozDaRochaCaetanoMunhozDa Rocha
452FALSERodoviaRaphaelDeAlmeidaMagalhaes/br-493/rj-109RaphaelDeMagalhaes/br-493/rj-109
Sheet1
Cell Formulas
RangeFormula
J2:J45J2=INDEX($C2:$H2,,$A2)
K2:K45K2=INDEX($C2:$H2,,$A2+1)
L2:L45L2=IF(B2=TRUE,F2&" "&INDEX($C2:$H2,,5),INDEX($C2:$H2,,5))
 
Upvote 0
Another option
Fluff.xlsm
ABCDEFGHIJK
1Starting rowParticle Test123456FIRSTMIDDLELAST
22TRUEAvenidaJuscelinoKubitschekDeOliveiraJuscelinoKubitschekDe Oliveira
32TRUERodoviaJuscelinoKubitschekDeOliveira/br-364/br-163JuscelinoKubitschekDe Oliveira/br-364/br-163
42FALSEEstradaFranciscoDaCruzNunesFranciscoDaCruz
52TRUEAvenidaAyrtonSennaDaSilvaAyrtonSennaDa Silva
62TRUERuaCláudioManoelDaCostaCláudioManoelDa Costa
72FALSERodoviaErnâniDoAmaralPeixoto/rj-106ErnâniDoAmaral
82TRUEAvenidaRaimundoPereiraDeMagalhãesRaimundoPereiraDe Magalhães
92TRUERodoviaJuscelinoKubitschekDeOliveira/br-364JuscelinoKubitschekDe Oliveira/br-364
102TRUERuaJuscelinoKubitschekDeOliveiraJuscelinoKubitschekDe Oliveira
113TRUERuaFreiHenriqueDeCoimbraHenriqueDeDe Coimbra
123TRUEAvenidaGalOsórioDePaivaOsórioDeDe Paiva
132TRUEAvenidaJoãoNavesDeÁvilaJoãoNavesDe Ávila
142TRUERuaPeroVazDeCaminhaPeroVazDe Caminha
152FALSERuaFernãoDiasPaesLemeFernãoDiasPaes
162TRUEAvenidaEduardoFróesDaMotaEduardoFróesDa Mota
174FALSERodoviaAnelRodoviárioCelsoMelloAzevedo/br-262CelsoMelloCelso
182FALSEAvenidaJoséBentoRibeiroDantasJoséBentoRibeiro
192FALSERuaCatuloDaPaixãoCearenseCatuloDaPaixão
202FALSEAvenidaJoaquimDaCostaLimaJoaquimDaCosta
212TRUEAvenidaBentoMunhozDaRochaNetoBentoMunhozDa Rocha
222TRUEAvenidaArmandoSallesDeOliveiraArmandoSallesDe Oliveira
232TRUEAvenidaAmadorBuenoDaVeigaAmadorBuenoDa Veiga
242FALSERuaTancredoDeAlmeidaNevesTancredoDeAlmeida
252FALSEAvenidaDorivalCândidoLuzDeOliveiraDorivalCândidoLuz
262TRUERodoviaFelicianoSallesDaCunha/sp-310FelicianoSallesDa Cunha/sp-310
273FALSEAvenidaJuízMarçoTúlioIsaacMarçoTúlioTúlio
282TRUEAvenidaOsvaldoJoséDoAmaralOsvaldoJoséDo Amaral
292FALSERodoviaEuclídesDeOliveiraFigueiredo/sp-563EuclídesDeOliveira
302TRUERuaJoséLinsDoRegoJoséLinsDo Rego
312TRUEAvenidaJoséPontesDeAlmeidaJoséPontesDe Almeida
322TRUERuaJoãoPereiraDaSilvaJoãoPereiraDa Silva
332TRUEAvenidaAdhemarPereiraDeBarrosAdhemarPereiraDe Barros
342TRUERuaIsmaelJoséDoNascimentoIsmaelJoséDo Nascimento
352TRUERuaBartolomeuBuenoDaSilvaBartolomeuBuenoDa Silva
363FALSERodoviaJoãoDaSilvaMaia/br-135DaSilvaSilva
372TRUERuaAyrtonSennaDaSilvaAyrtonSennaDa Silva
383FALSEAvenidaPastorMartinLutherKingJrMartinLutherLuther
392TRUEAvenidaMozartPinheiroDeLucenaMozartPinheiroDe Lucena
402FALSEAvenidaGetúlioDornelesVargas-NGetúlioDornelesVargas
412TRUEAvenidaMárioHomemDeMeloMárioHomemDe Melo
422FALSEAvenidaDanielDeToucheDanielDe
433FALSEAvenidaPastorMartinLutherKingJúniorMartinLutherLuther
442TRUERuaCaetanoMunhozDaRochaCaetanoMunhozDa Rocha
452FALSERodoviaRaphaelDeAlmeidaMagalhaes/br-493/rj-109RaphaelDeAlmeida
Data
Cell Formulas
RangeFormula
I2:J45I2=INDEX(C2:H2,,A2+{0,1})
K2:K45K2=IF(B2,TEXTJOIN(" ",,INDEX(F2:G2,,0)),F2)
Dynamic array formulas.
 
Upvote 0
As both solutions give different results, did either of them give the result you are after?
 
Upvote 0
As both solutions give different results, did either of them give the result you are after?
I'm checking on both of them as we speak. I will probably be able to modify the formulas to reach what I need if the solutions the two of you provided do not match exactly what I need, thank you very much!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
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