PDA

View Full Version : How can I concat a Do While result?



RikardoMX
05-25-2022, 12:33 AM
Hello everyone.
I'm trying to concatenate the data from Col "F", following by a ";" and paste the result in Cell "L2".
I tried several time without success.

This is my code:

Fila =6 'Info starts in F6
Do While Range("F" & Fila) <>""
Fila=Fila+1

I tried with
ActiveCell.Formula2R1C1="=Concat(Fila & ""; "")"
(obviously is wrong)

I want this as example:
in F6 = Perez, Ricardo
in F7 = Perez, Patricia
as result in L2= Perez, Ricardo; Perez, Patricia

Thanks. I'm a beginner with the VBA.

rollis13
05-25-2022, 04:24 AM
This could be a solution:
Option ExplicitSub test()
Dim Fila As Long
Fila = 6 'Info starts in F6
Do While Range("F" & Fila) <> ""
Range("L2") = Range("F" & Fila) & "; " & Range("F" & Fila + 1)
Fila = Fila + 2
Loop
End Sub

RikardoMX
05-25-2022, 06:32 AM
The Do While is working, but L2 doesn’t show me all the data. Only show me the data from 2 rows.


This could be a solution:
Option ExplicitSub test()
Dim Fila As Long
Fila = 6 'Info starts in F6
Do While Range("F" & Fila) <> ""
Range("L2") = Range("F" & Fila) & "; " & Range("F" & Fila + 1)
Fila = Fila + 2
Loop
End Sub

rollis13
05-25-2022, 11:30 AM
I was following your example thinking you just needed a track, then you would've customized it by yourself.
Option Explicit
Sub test()
Dim Fila As Long
Fila = 6 'Info starts in F6
Do While Range("F" & Fila) <> ""
Range("L2") = Range("L2") & Range("F" & Fila) & "; "
Fila = Fila + 1
Loop
End Sub

RikardoMX
05-25-2022, 09:47 PM
I analyzed what I need, and I detected that there is other way to obtain the result without Concat.
I appreciate your time. Your comment helps me to understand the Do While

rollis13
05-25-2022, 10:09 PM
In fact, I haven't used Concat either ;).