• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Code

BhuSan

New Member
Hello All,

I need a VBA code to copy and paste the entire column to next column. which means I need to duplicate to the new column. I have attached a test data file which shows column A to E. I need to insert a new column after A and copy and paste all the data in Column A to Column B. See the attached File. See the desired result I want to second sheet.

There are more than 300 columns on data.

Thanks for in advance for you help.
 

Attachments

  • Test.xlsx
    9 KB · Views: 1
Use Record Macro and perform operation manually.

This is the resulting code.
Code:
Sub Macro1()
    Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
End Sub

Now you have base code to work with.

Edit: Woops submitted before writing everything. Continued.
 
You have to use For Loop to repeat operation and skip when variable equals i + 1 (every other i).

So use n as second variable and do logic check that if "i" = n + 1 add +1 to "i" to skip.
Code:
Sub Macro1()
Dim n As Long
Dim i As Long

n = 1

For i = 1 To 10
    If i = n + 1 Then
        i = i + 1
    End If
  
    Columns(i).Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns(i + 1).Select
    Selection.Insert Shift:=xlToRight
    n = i

Next i
End Sub
 
Back
Top