+ Reply to Thread
Results 1 to 7 of 7

Deleting columns based on cell value

  1. #1
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Deleting columns based on cell value

    Hi all,

    I'm hoping one of you guys can help me out here. I have a spreadsheet (attached is a mock version) where I need to delete columns based on which cells are empty.

    On the 'helper' tab, cell A5 (with the help of other formulas) identifies which cells are blank on the 'fullschedule' tab. I then had to write each macro to suit each combination of cells that were empty, but the number of combinations was getting out of control.

    So for example, if A5 on the 'Helper' tab identifies that cells 'CILNPX' on the 'Fullschedule' tab are empty (which it has in the attached), how can I get columns CILNPX on the 'FullSchedule' tab to delete when the macro runs?

    Thank you in advance for your time, I've looked around and can't find much to help me on this.
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Deleting columns based on cell value

    Hello Reapz,

    Excel formula macros can not delete rows or columns. This can only be done using a VBA macro.

    Unfortunately, VBA macros will not run when formulas are recalculated. They can run automatically when the workbook is opened, a cell's contents are changed by the user, a button is clicked, or the user runs the macro using the Macro Dialog.

    Will any of these options work for you?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Deleting columns based on cell value

    Even the Helper Sheet is not required since we can identify the blank column headers in VBA code itself

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Deleting columns based on cell value

    Quote Originally Posted by Leith Ross View Post
    VBA macros will not run when formulas are recalculated
    Just wondering whether this can able to do the autorun rask

    Please Login or Register  to view this content.
    Please correct me if I am wrong

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Deleting columns based on cell value

    As well as Sixthsense's clever solution, have a look at berlan's and my solution here where though the macros suggested hide columns, they could be easily modified to delete them.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Deleting columns based on cell value

    Thanks guys. Sorry for the late reply!

    I tried it on the worksheet I uploaded and it works awesomely, but I'm now trying it in the actual spreadsheet I made up (a LOT bigger) and I just can't it working. I'll persevere with it this afternoon/tomorrow and get back to you. Appreciate the responses, I'm amazed by your guys knowledge.

  7. #7
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Deleting columns based on cell value

    Hey guys, sorry to bring this back from the dead, SixthSense has been extremely helpful in helping me with this but I feel like an attached version would help speed the process up/lower the confusion.

    The attached file has 3 tabs.
    - The first tab "FullSchedule" is the one with all the data in it that needs to be formatted so the rest of my code will work (in another file unrelated).
    - The second tab has the raw data that can be copy/pasted into 'FullSchedule' if the code fails.
    - The third tab is what the data should look like if the macro works perfectly.

    Due to the SAP exports leaving random columns empty, sometimes it has two blank columns next to each other (in this case, columns O & P).

    The macro's I have from SixthSense's help are:

    1. "ThisKindOfWorks" macro does exactly what I need it to do, but does not delete column P (which becomes column L once every other blank column from row 9 (except for column C) is deleted.
    2. "DeleteBlankColumnHeaderColumns" - Is the code that goes from right to left, but it seems to delete almost everything.

    Sorry for the essay, appreciate any help available. Cheers. +rep for any assistance!

    Edit: Just quickly - some clarification. When the SAP export has 1 empty column, then a full column etc etc, the macro 'ThisKindOfWorks' actually works really well. It's only when there's two empty columns next to each other that the code doesn't work fully..

    Edit #2 - I've figured out how to get it to work by running the macro twice. I'll try work out how to get it to work by using this method unless someone has any better ideas. Thanks again for any help.

    Edit #3 - Totally figured it out and implemented it into my project. Would like to publicly thank SixthSense for all of his help. Solved.
    Attached Files Attached Files
    Last edited by Reapz; 03-03-2015 at 07:01 PM. Reason: Clarification

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Deleting Columns based on Cell Values VBA
    By Matty5894 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2014, 08:58 AM
  2. [SOLVED] Deleting multiple columns based on columns' first row value
    By {=OR(value=array)} in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2014, 04:00 PM
  3. [SOLVED] Deleting rows based on a certain columns 'prefixes'?
    By Mgassma in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-02-2013, 03:40 PM
  4. deleting rows based on value in columns.
    By barksmith in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-28-2009, 12:21 PM
  5. [SOLVED] Deleting Columns Based upon Heading
    By Jessica in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2005, 07:10 PM

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