1

So in a document I wish to convert a column of letters into a single cell. For example if the column contained the letters h,e,l,l,o then the program would put into a single cell "hello". I attempted to do this with the following code but it leaves the output cell blank

Dim t1 As String
Dim t2 As String

Do While Cells(i, "B").Value <> ""
t2 = Cells(i, "D").Value
t1 = Cells(i, "B").Value
Cells(i, "D").Value = t1 & t2
i = i + 1
Loop
1
  • 2
    Office 365 exel: =CONCAT(B1:B5) Commented Sep 15, 2017 at 16:15

2 Answers 2

3
Function MyConcat(rng as range)
    dim rngEach as Range
    For Each rngEach in rng            
        MyConcat = MyConcat & rngEach.Value      
    Next rngEach
End Function

Then in the cell put: =MyConcat(B1:B5)

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Discarding blanks would be appropriate if you were adding a delimiter however.
1

There is no need to use VBA for this. Excel has built in function CONCATENATE().

Use it like this:

In the cell where you need the output enter the formula

=CONCATENATE(Select cell 1, select cell2,select cell3)

So you can select all the cells which you want to join. Put a comma in between each cell.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.