Export to Excel and Insert Column - Export works, insert doesn't

KBertsch

New Member
Joined
Jun 25, 2010
Messages
8
Hello,

I need to export from a program called QV into Excel, and insert a column before the existing column "X".

Here's my code so far:

Sub ExportToExcel()
Const xlShiftToRight = -4161
Set XLApp = CreateObject("Excel.Application") 'Creating excel instance in VB Script
XLApp.Visible = True 'Setting the value to False, so this happens in background
Set XLDoc = XLApp.Workbooks.Add 'Creating new excel workbook

XLDoc.Sheets(1).Name = "Auditor WS" 'Adding the sheet name as Export
Set XLSheet = XLDoc.Worksheets(1) 'Setting the XLSheet
Set MyTable = ActiveDocument.GetSheetObject("CH47") 'Setting MyTable variable to current QlikView Object
MyTableCount = MyTable.GetRowCount

Set XLSheet = XLDoc.Worksheets(1) 'Select sheet where data should be pasted
Mytable.CopyTableToClipboard True 'Copy data to Clipboard
XLSheet.Paste XLSheet.Range("A1") 'Paste data starting at a1
Set objRange = objExcel.Range("Y1").EntireColumn
objRange.Insert(xlShiftToRight)
End Sub

This successfully opens Excel, and copies over the information from the table in QlikView.

However, it does not insert the column.

What am I missing here?

Thanks!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
might need to add the sheet to this

Code:
Worsheet(XLSheet).Range("Y:Y").EntireColumn.Insert
 
Upvote 0
here is a sample


Code:
Range("B5:HT5").Copy
Range("B5:HT5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,226
Members
449,303
Latest member
grantrob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top