Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default cant add a column in vb code


I have opened a spreadsheet and am trying to add a column

if I use the following

selection.Insert Shift:=xlToRight

this works on the first iteration but fails on the second with the
following error
object variable or with block not set.

If i try the following

xlWks.Columns.Insert Shift:=xlToRight i get the message
cannot shift non blank cells off worksheet.

However the worksheet is off limited size (36 rows and 20 columns) and
is
borfered by blank cells none of which have associated formula


--
helenmacduff
------------------------------------------------------------------------
helenmacduff's Profile: http://www.excelforum.com/member.php...o&userid=29020
View this thread: http://www.excelforum.com/showthread...hreadid=487525

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default cant add a column in vb code

Helen

borfered by blank cells none of which have associated formula


....You may think so, but if you press Ctrl and right arrow you will find
that data extends way beyond where you think it is... Inserting cells,
whether they now have data/formulas or not will be seen by Excel as 'Used'

You second example is moving the columns collection (the whole lot) to the
right, that will not work as it tries to move 256 columns to another 256
'spaces' to the right that don't exist.

You could try resetting the usedrange after each insert and saving, if you
persist with the first route

Sheet1.UsedRange
ActiveWorkbook.Save

If that doesn't work then try deleting entire columns and saving the
workbook (Similar to your second route)

Selection.EntireColumn.Insert

HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
HIS


"helenmacduff"
wrote in message
news:helenmacduff.1yxtda_1132728602.0501@excelforu m-nospam.com...

I have opened a spreadsheet and am trying to add a column

if I use the following

selection.Insert Shift:=xlToRight

this works on the first iteration but fails on the second with the
following error
object variable or with block not set.

If i try the following

xlWks.Columns.Insert Shift:=xlToRight i get the message
cannot shift non blank cells off worksheet.

However the worksheet is off limited size (36 rows and 20 columns) and
is
borfered by blank cells none of which have associated formula

helenmacduff

------------------------------------------------------------------------
--


helenmacduff's Profile:
http://www.excelforum.com/member.php...o&userid=29020
View this thread: http://www.excelforum.com/showthread...hreadid=487525



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default cant add a column in vb code


the selection is a method off xlapp

so xlapp.selection.entirecolumns.insert works


--
helenmacduff
------------------------------------------------------------------------
helenmacduff's Profile: http://www.excelforum.com/member.php...o&userid=29020
View this thread: http://www.excelforum.com/showthread...hreadid=487525

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill column from data (code) in column next to it Matt Excel Worksheet Functions 4 April 24th 09 06:17 PM
what is the code to delete row&column. areddy[_23_] Excel Programming 1 November 9th 05 12:41 PM
VB code to sum up all the figures in a column tanks1308[_2_] Excel Programming 1 August 5th 04 11:46 PM
Reference a Column in Code Wally Steadman[_3_] Excel Programming 1 November 17th 03 11:26 AM
Column Code DaveB[_2_] Excel Programming 3 October 23rd 03 05:21 PM


All times are GMT +1. The time now is 11:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"