+ Reply to Thread
Results 1 to 3 of 3

Error running delete columns macro

  1. #1
    Registered User
    Join Date
    12-26-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Error running delete columns macro

    I keep getting errors running the following macro. I am a novice at this but it seems simple enough though I keep getting the error in different places in the code each time I open and close the worksheet.


    Please Login or Register  to view this content.
    Sub COFormat()
    '
    ' CriticalOrdersFormat Macro
    '

    Sheets("Data").Select

    Columns("I:L").Select
    Selection.Delete Shift:=xlToLeft
    Columns("O:P").Select
    Selection.Delete Shift:=xlToLeft
    Columns("Q:R").Select
    Selection.Delete Shift:=xlToLeft
    Columns("T").Select
    Selection.Delete Shift:=xlToLeft
    Columns("A").NumberFormat = "m/d/yyyy;@"
    Columns("Q").NumberFormat = "m/d/yyyy;@"
    Columns("R").NumberFormat = "m/d/yyyy;@"
    Columns("S").NumberFormat = "m/d/yyyy;@"
    Columns("U").NumberFormat = "m/d/yyyy;@"
    Columns("X").NumberFormat = "m/d/yyyy;@"
    Columns("Y").NumberFormat = "m/d/yyyy;@"
    Columns("AB").NumberFormat = "m/d/yyyy;@"

    End Sub
    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Error running delete columns macro

    Hi,first of all you should place your code between tags - select your text then hit the # on the tool bar.

    Regards your problem, you need to deal with the columns furthest from cloumn A first.
    If you delete say column B, then cloumn C becomes B, D becomes C etc.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: Error running delete columns macro

    I ran this with no errors, is your sheet protected

    Please Login or Register  to view this content.
    Last edited by GaidenFocus; 12-26-2012 at 05:00 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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