cant add a column in vb code

  • Thread starter Thread starter helenmacduff
  • Start date Start date
H

helenmacduff

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
 
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
(e-mail address removed)


"helenmacduff" <[email protected]>
wrote in message
 
the selection is a method off xlapp

so xlapp.selection.entirecolumns.insert works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top