+ Reply to Thread
Results 1 to 6 of 6

Thread: How to delete columns using VBA excel?

  1. #1
    Registered User
    Join Date
    09-30-2009
    Location
    casablanca
    MS-Off Ver
    Excel 2007
    Posts
    9

    How to delete columns using VBA excel?

    Hi everybody, i have a "beginer" question, i have an excel file with a lot of sheets, and every sheets contain at least one table but in different position, what i wanna do is delete all empty columns before the tables on each sheet, in order to have all the start on the same "B" column.

    i tried to tinker a small macro but it doesnt work :

    Sub DeleteColumns()
    
    Worksheets(2).Activate
    Worksheets(2).Range("B1:B100").Select
    If Sum(Selection).Value = 0 Then
        Column("B").EntireColumn.Delete
        Else
    
    End Sub
    Thank you for your help.
    Last edited by anasleco; 12-06-2011 at 07:32 AM. Reason: conform to rule 3 of the forum

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    6,566

    Re: How to delete columns using VBA excel?

    Is there anything common contained within each table, and unique to the table on each sheet? e.g. a column label or table header/description. Knowing this would allow a macro to determine the position of the table and hence be able to delete all the columns to the left.

    Please update us and no doubt someone will come up with a solution.

    Regards
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  3. #3
    Registered User
    Join Date
    09-30-2009
    Location
    casablanca
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to delete columns using VBA excel?

    in fact the common thing between all the sheets is that the columns ti the left of the table are empty.

  4. #4
    Registered User
    Join Date
    09-30-2009
    Location
    casablanca
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to delete columns using VBA excel?

    I'm sorry for that, i've edited my post.

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

    Re: How to delete columns using VBA excel?

    sub snb()
      for each sh in sheets
        sh.columns(1).resize(,sh.usedrange.columns(1).column-1).delete
      next
    end sub



  6. #6
    Registered User
    Join Date
    09-30-2009
    Location
    casablanca
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to delete columns using VBA excel?

    thnaks everybody for the great help

+ 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.2.0