+ Reply to Thread
Results 1 to 8 of 8

Delete Column if empty.

  1. #1
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Delete Column if empty.

    After dealing with deleting rows, I figured if I changed a few variables and I could make it delete columns instead of rows...

    Here is what I came up with.

    Please Login or Register  to view this content.
    Obviously it didn't work... so I looked around for an answer, I found this code:

    Please Login or Register  to view this content.
    Now out of what I learned from the code in the delete cells, I understand most of this, but the only thing I am looking at here, that makes me pause is the the comments.

    What I thought would work would be this:

    Please Login or Register  to view this content.
    But this doesn't work either, so if someone could clarify what is going on, it be greatly appreciated.

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Delete Column if empty.

    try this
    Please Login or Register  to view this content.
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to rate it. To thank someone who has helped you, click on the star icon below their name.
    - This way you will add him some reputation points ... thanks in advance.

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Delete Column if empty.

    On what basis do you want to delete the columns? As long as they are completely empty?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Delete Column if empty.

    Quote Originally Posted by arlu1201 View Post
    On what basis do you want to delete the columns? As long as they are completely empty?
    What I'd like to do is have something like the first code, where it has the criteria already spelled out before the code starts, and then in between the columns delete any empty columns depending on if data is in a specific row or not.

  5. #5
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Delete Column if empty.

    The following code assumes that the first row is a header row. If there is nothing below row 1, the column is deleted.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Delete Column if empty.

    Quote Originally Posted by StevenM View Post
    The following code assumes that the first row is a header row. If there is nothing below row 1, the column is deleted.

    Please Login or Register  to view this content.
    How do I change it to make row 6 the row it searches?

    Please Login or Register  to view this content.
    Do I change the 1 there to 5 or 6?

    The other issue is I don't see the ability to adjust columns it searches I may need to select, because A will not always need to be "removed"
    Last edited by Cyberpawz; 04-10-2012 at 02:56 PM.

  7. #7
    Forum Contributor
    Join Date
    11-11-2007
    Posts
    263

    Re: Delete Column if empty.

    Ok, found something that works, but not entirely. It copies the data, but doesn't delete the original. If someone can help with that last aspect it be greatly appreciated...the other bit, would make it work with only the 2nd sheet in a workbook... I thought I did it by adding in Workbook(2) into right after the Dim cell, but it doesn't work, it ignores it.

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Delete Column if empty.

    Please Login or Register  to view this content.
    The variable ".Cells(.Rows.Count, i).End(xlUp).Row" will return the last row in column "i" which is not empty.

    Thus if one wanted to delete every column which doesn't have information below row 6, one could change it to:

    Please Login or Register  to view this content.
    But you might also need to change the line:

    Please Login or Register  to view this content.
    Where "6" then is the header row.

+ 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