View Full Version : [SOLVED:] How do I create a new column next to a specific column using VBA?
doctortt
11-25-2013, 10:06 AM
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
Paul_Hossler
11-25-2013, 12:28 PM
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
doctortt
11-25-2013, 12:50 PM
Yes, they codes work. Thanks
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.