View Full Version : [SOLVED:] Create new column
omidvakili
04-15-2020, 11:03 AM
Hi Guys
We have a series of columns,
We want to create a new page that:
Combining each column with other columns will create a new column, for example for column A, columns of AB, AC, AD, AE and AF should be created.
For columns B, columns of BC, BD, BE and BF should be created.
Finally, we need a code automatically creates these columns.
26332
paulked
04-15-2020, 12:19 PM
Hi and welcome to the forum.
Naming your columns A, B, C... is confusing eg Column A could contain "" Z Y X W... or 1 0 1 1...
I'm guessing you want something like this
26333
Which can be done with this
Sub test()
Dim ar, i As Long, j As Long, k As Long
ar = Range("B2:G8")
k = 8
For i = 1 To 5
k = k + 1
For j = 2 To 8
Cells(j, k) = ar(j - 1, i) & ar(j - 1, i + 1)
Next
Next
End Sub
Format the destination cells as text.
omidvakili
04-16-2020, 02:59 AM
Thanks a lot Paulked.
I think I couldn't express my mean but fortunately I found the solution:
Sub Blah()
Set Source = Range("B1:G1")
Set Destn = Range("H1")
For g = 1 To 5
For h = g + 1 To 6
Destn.Value = Join(Array(Source.Cells(g), Source.Cells(h)), "")
Set Destn = Destn.Offset(1)
Next
Next
End Sub
p45cal
04-16-2020, 04:14 AM
Looks like an adaptation of my code from somewhere!
omidvakili
04-16-2020, 02:13 PM
That's right.
I changed it.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.