PDA

View Full Version : Sleeper: Copy column



Dreamer
09-05-2005, 11:04 PM
Hi all,

If there are 3 variables in row 1, KA01, KE01 & KG01..
How can I copy KA01's column x 3 times, insert the new column next it, name it as KB01,KC01 and KD01, copy KE01, name it "KF01", copy KG01 & name it "KH01" ?

The result will look like...
KA01,KB01,KC01,KD01,KE01,KF01,KG01,KH01 shown in row1
KA01,KB01,KC01,KD01= same content with different headers
KE01,KF01= same content with different headers
KG01,KH01= same content with different headers

MANY THANKS!

mdmackillop
09-05-2005, 11:54 PM
Hi Dreamer,
The following code will copy the column of the selected header one column to the right and increment the second letter of the header cell. Please note that the code will fail if the selected cell is not in row 1. If this is a problem, let me know.
Regards
MD

Sub DoCopy()
Dim Tmp as string
ActiveCell.EntireColumn.Copy
ActiveCell.Offset(0, 1).Insert Shift:=xlToRight
ActiveCell.Offset(0, 1).Select
Tmp = Asc(Mid(ActiveCell, 2, 1))
ActiveCell.Value = Left(ActiveCell, 1) & Chr(Tmp + 1) & Right(ActiveCell, 2)
Application.CutCopyMode = False
End Sub