Results 1 to 6 of 6

Thread: How can I concat a Do While result?

  1. #1
    Junior Member
    Join Date
    May 2022
    Posts
    3
    Rep Power
    0

    How can I concat a Do While result?

    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.

  2. #2
    Member rollis13's Avatar
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0
    This could be a solution:
    Code:
    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

  3. #3
    Junior Member
    Join Date
    May 2022
    Posts
    3
    Rep Power
    0
    The Do While is working, but L2 doesn’t show me all the data. Only show me the data from 2 rows.

    Quote Originally Posted by rollis13 View Post
    This could be a solution:
    Code:
    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

  4. #4
    Member rollis13's Avatar
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0
    I was following your example thinking you just needed a track, then you would've customized it by yourself.
    Code:
    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

  5. #5
    Junior Member
    Join Date
    May 2022
    Posts
    3
    Rep Power
    0
    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

  6. #6
    Member rollis13's Avatar
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0
    In fact, I haven't used Concat either .
    Last edited by rollis13; 01-08-2024 at 02:08 AM.

Similar Threads

  1. Replies: 10
    Last Post: 08-26-2020, 10:59 PM
  2. Replies: 30
    Last Post: 04-15-2019, 07:36 PM
  3. Replies: 9
    Last Post: 12-29-2017, 02:51 PM
  4. CONCAT into one cell based on 2 values
    By shelbsassy in forum Excel Help
    Replies: 3
    Last Post: 07-06-2017, 08:20 AM
  5. Find the highest then lookup result
    By Stalker in forum Excel Help
    Replies: 4
    Last Post: 04-02-2013, 02:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •