Transform columns with VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I have the following problem that I would like to solve with a VBA-macro

In column A there is a string of letters and/or numbers in every cell, e.g. A1-A6
a
za
b
hg
v
z

I would like to buikd a new column B in the following way: The content of A2 goes behind A1, the content of A3 goes behind A2 and so on

In the exemple above the column B is
abza
zabb
b2hg
hgfv
vaz

Does anybody know a VBA-macro that does this job

Kind regard
Michael E
 
On the offhand chance a simple formula can be used:

in B2 or B1, your choice, but a formula

=A1&A2

then drag fill down the column.

--
Regards,
Tom Ogilvy

Michael E. said:
Hello,

I have the following problem that I would like to solve with a VBA-macro:

In column A there is a string of letters and/or numbers in every cell, e.g. A1-A6:
ab
zab
b2
hgf
va
zb

I would like to buikd a new column B in the following way: The content of
A2 goes behind A1, the content of A3 goes behind A2 and so on.
 
Hello Tom

since the transformation should be included in an existing VBA macro I need a VBA solution. Do you know how a macro solution

Kind regard
Michae

----- Tom Ogilvy wrote: ----

On the offhand chance a simple formula can be used

in B2 or B1, your choice, but a formul

=A1&A

then drag fill down the column

-
Regards
Tom Ogilv
 
For i = 1 To 5
Range("B" & i).Value = Range("A" & i).Value & Range("A" & i + 1).Value
Next

Alan Beban
 
Sub Concatenate2()
Range("B1:B5").Formula = "=A1&A2"
Range("B1:B5").Formula = Range("B1:B5").Value
End Sub


--
Regards,
Tom Ogilvy


Michael E. said:
Hello Tom,

since the transformation should be included in an existing VBA macro I
need a VBA solution. Do you know how a macro solution?
 
Alan Beban said:
For i = 1 To 5
Range("B" & i).Value = Range("A" & i).Value & _
Range("A" & i + 1).Value
Next
....

Range("B1:B5").Value = Evaluate("=A1:A5&A2:A6")

would be an alternative.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top