Create Column in Excel

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Create Column in Excel

Post by JRL » Tue Nov 19, 2019 5:36 pm

Does anyone have a method to insert a column into an existing Excel worksheet? I am looking to see if VBScript can do this but if someone already has a way I'd appreciate hearing about it.

For example: I want to insert a column after C and call it "Area"

Before

Code: Select all

	A		B		C		D		E
	Length		Width		Height		Error		Phase
After

Code: Select all

	A		B		C		D		E		F
	Length		Width		Height		Area		Error		Phase
Thank you,
Dick

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Create Column in Excel

Post by JRL » Tue Nov 19, 2019 6:11 pm

Found an answer HERE

Code: Select all

VBStart
  Const xlToRight = -4161
  Set objExcel = CreateObject("Excel.Application")
  objExcel.Visible = True
  Set objWB = objExcel.Workbooks.Open("I:\dick\TableTabFiles\Router_Lines_Used_Since_2018.xlsx")
  Set objSheet = objwb.Sheets("Sheet1")
  objSheet.Columns("D:D").Insert xlToRight
  objWB.Close True
  objExcel.Quit
VBEND
After that I can use XLSetCell> to Give the column a label and to insert my data.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts