VBA code for Concat

Anonymous
2022-04-22T06:39:26+00:00

Hi,

I have two arrays or ranges. Need to join the ranges across rows with delimiter "|" and it has to stored as new array as per below image.

C

Required VBA code for desired output array and it to store with new name

Tried using concat function as provided below but it doesn't work.

Dim RowName1 As String

Dim RowName2 As String

RowName = Application.WorksheetFunction.Concat(Range(RowName1).Value, "|", Range(RowName2).Value)

Thanks in Advance

Microsoft 365 and Office | Excel | For education | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Andreas Killer 144K Reputation points Volunteer Moderator
    2022-04-22T07:09:27+00:00

    It makes no sense to use VBA / UDF or CONCAT here. Use a simple formula like =A2&"|"&B2 and drag down.

    Andreas.

    0 comments No comments
  2. Anonymous
    2022-04-22T07:23:39+00:00

    Thanks for reply,

    I would require in VBA only. Because it is input to the other piece of code.

    0 comments No comments
  3. Andreas Killer 144K Reputation points Volunteer Moderator
    2022-04-22T10:05:15+00:00

    Well, it is not possible to give accurate information based on your screenshot.

    On the other hand, if you loop through the rows (with your other code) the concatenate is simple like
    Range("D" & ThisRow) = Range("A" & ThisRow) & "|" & Range("B" & ThisRow)

    If you need further help please upload your file (maybe with anonymous data) on an online file hoster like https://www.dropbox.com and post the download link here.

    Andreas.

    0 comments No comments