Consulting

Results 1 to 3 of 3

Thread: How do I create a new column next to a specific column using VBA?

  1. #1

    How do I create a new column next to a specific column using VBA?

    Hi, Let say I have an existing column called "TEST" in A1. How do I create VBA codes to do this: create a new column called "TEST2" to the right of "TEST" Thanks
    Last edited by doctortt; 11-25-2013 at 12:31 PM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    probably need to tweak this a bit


    Option Explicit
    Sub Macro1()
        Dim iFindCol As Long
        
        iFindCol = 0
        On Error Resume Next
        iFindCol = Application.WorksheetFunction.Match("TEST", ActiveSheet.Rows(1), 0)
        On Error GoTo 0
        If iFindCol = 0 Then Exit Sub
        
        Call ActiveSheet.Columns(iFindCol + 1).Insert(xlShiftToRight)
        ActiveSheet.Cells(1, iFindCol + 1).Value = "TEST2"
    
    End Sub
    Paul

  3. #3
    Yes, they codes work. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •