+ Reply to Thread
Results 1 to 9 of 9

Delete Columns if Criteria matched.

  1. #1
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Delete Columns if Criteria matched.

    Hey guys, I am again stumped on the syntax for this code. If someone could take a look at it for me I would appreciate it very much.

    I am trying to step through a dynamic range in both columns and rows and delete any columns that have value of "0". In row 1 is the headers for each column.

    I think the problem is with the variable "col"???

    Please Login or Register  to view this content.
    Thanks
    Last edited by JapanDave; 12-20-2011 at 04:32 AM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete Columns if Criteria matched.

    maybe so
    Please Login or Register  to view this content.

  3. #3
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete Columns if Criteria matched.

    nilem, thanks for that.

    Could you explain how this line stores the columns to be deleted? I can't get my head around it???
    Please Login or Register  to view this content.

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete Columns if Criteria matched.

    We combine cells of certain columns to be removed in the range 'colDe'. And then delete the columns at a time.
    It's faster than deleting columns in series in the loop.

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete Columns if Criteria matched.

    Thanks for the explanation, but I still can't see how that code stores the data? I thought you needed something like "Static" to store the data collected by the code?

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete Columns if Criteria matched.

    Let's try again
    Please Login or Register  to view this content.
    i - the column number that we are going to remove.
    .Cells (1, i) - a cell of the column we are going to remove it.
    colDel- this is unrelated range of cells belonging to the columns that we are going to remove it.

  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete Columns if Criteria matched.

    Ahh, I see now.
    And please forgive the questions.
    However, I don't know how you can set the same variable twice?

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete Columns if Criteria matched.

    Quote Originally Posted by JapanDave View Post
    ...However, I don't know how you can set the same variable twice?
    You mean 'colDel' variable?
    Try this code for example.
    Please Login or Register  to view this content.

  9. #9
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete Columns if Criteria matched.

    Hey Nilem,
    I have got now. Thanks so much for the detailed explanation. The union ties the ranges together, then you can act on that how ever you want.

    Dave

+ 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