+ Reply to Thread
Results 1 to 6 of 6

Cannot Insert Column VBA

Hybrid View

atardif Cannot Insert Column VBA 07-21-2011, 06:44 PM
tigertiger Re: Cannot Insert Column VBA 07-21-2011, 06:58 PM
atardif Re: Cannot Insert Column VBA 07-23-2011, 07:23 PM
atardif Re: Cannot Insert Column VBA 07-24-2011, 12:03 AM
johnjohns Re: Cannot Insert Column VBA 07-24-2011, 03:15 AM
snb Re: Cannot Insert Column VBA 07-24-2011, 06:23 AM
  1. #1
    Registered User
    Join Date
    07-21-2011
    Location
    sydney, australia
    MS-Off Ver
    Excel 2011
    Posts
    3

    Exclamation Cannot Insert Column VBA

    Dear All

    I would greatly appreciate your help on this, because I am going crazy.

    I have a spreadsheet filled with data (no merged cells) and I created a macro to sort the spreadsheet. Everything was working perfectly, until I tried to insert a column using code at the beginning of the macro.

    The code is
         Columns("A:A").Select
        Selection.Insert Shift:=xlToRight
    When the macro now runs, the first row acts as if a column has been inserted, i.e it shifts to the right, but the remainder of the spreadsheet does not.

    I've tried shifting data to a new sheet, creating a new module, inserting another column, nothing works!!! However, if I step-into the macro, after stepping over the code once (where it does as above), when I shift the cursor above the code and step over it again, it inserts the column!

    This is driving me to distraction, any thoughts or help would be greatly appreciated!!

    Thanks
    Alex

  2. #2
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470

    Re: Cannot Insert Column VBA

    try the alternative

     Columns("A:A").Insert shift:=xltotright
    or

     ActiveSheet.Columns("A:A").Insert shift:=xltotright
    Best regard, -)iger-/iger
    If you are pleased with a solution mark your post SOLVED.

  3. #3
    Registered User
    Join Date
    07-21-2011
    Location
    sydney, australia
    MS-Off Ver
    Excel 2011
    Posts
    3

    Re: Cannot Insert Column VBA

    Hi tigertiger,

    thanks for your help, but unfortunately it didn't work.
    When I inserted the code and manually went through it, it worked fine, however when I ran the code automatically, I got a runtime error 1004, insert method of range class failed.

    Why would it work manually but not automatically?

  4. #4
    Registered User
    Join Date
    07-21-2011
    Location
    sydney, australia
    MS-Off Ver
    Excel 2011
    Posts
    3

    Re: Cannot Insert Column VBA

    Hi Radiant, Michael

    Thanks for your efforts, but no luck unfortunately.

    I thought it might be useful for you to see the buildup to the code. Also, I am using MO 2011. The code is massive, but this is everything that appears before the insert column code. Basically this macro is sorting out a mass of data into some semblance of order - Sub MainC() is where the error occurs.

    I have attached as a txt file


    Thanks again
    Alex
    Attached Files Attached Files
    Last edited by atardif; 07-24-2011 at 12:06 AM.

  5. #5
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Cannot Insert Column VBA

    Perhaps a sample workbook could be of more help. We can then see what actually happens.
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Cannot Insert Column VBA

    Start clearing your code:

    - do not use select
    - do not use activate
    - refer to the sheets unequivocally by using it's name e.g.: sheets("hotel') sheets("manager")
    - dive into the VBEditor's help about loops : For...Next
    - avoid errorhandlers



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1