How about (try it):
Sub AddCol()
Dim rng As Range, c As Range, i as long
for i = 1 to 3
Set rng = Intersect(ActiveSheet.UsedRange, Rows(2)) ' Isolate row 2
If rng Is Nothing Then Exit Sub ' Assuming there is more than one row
Set c = rng.Cells(rng.Cells.Count) ' Isolate the last cell in row 2
If IsEmpty(c) Then Set c = c.End(xlToLeft) ' Find the last non-empty cell
If Not IsEmpty(c) Then
Set rng = Intersect(c.EntireColumn, ActiveSheet.UsedRange) ' Isolate the used area of the column
rng.Copy ' Copy to clipboard
rng.Insert Shift:=xlToRight ' Duplicate
c.Offset(0, -1).Select ' Select the "marker" in the duplicate column
Application.CutCopyMode = False ' Switch off the CutCopy marquee
End If
next i
End Sub
I just added two lines and one declaration of variable. Looking at the structure - it shall work. Or if I understand wrong your concept - try another mod:
Sub AddCol()
Dim rng As Range, c As Range, i as long
Set rng = Intersect(ActiveSheet.UsedRange, Rows(2)) ' Isolate row 2
If rng Is Nothing Then Exit Sub ' Assuming there is more than one row
Set c = rng.Cells(rng.Cells.Count) ' Isolate the last cell in row 2
for i = 1 to 3
If IsEmpty(c) Then Set c = c.End(xlToLeft) ' Find the last non-empty cell
If Not IsEmpty(c) Then
Set rng = Intersect(c.EntireColumn, ActiveSheet.UsedRange) ' Isolate the used area of the column
rng.Copy ' Copy to clipboard
rng.Insert Shift:=xlToRight ' Duplicate
c.Offset(0, -1).Select ' Select the "marker" in the duplicate column
Application.CutCopyMode = False ' Switch off the CutCopy marquee
Set c = c.offset(0,-2) 'not sute about it: may be -1 - experiment with it
End If
next i
End Sub
just a small tip:
Next time post a tiny sample workbook with few input data and desired (manualy "calculated") results.
It makes much easier to test few concepts and choose the best one for those who try to help.
Bookmarks