+ Reply to Thread
Results 1 to 9 of 9

Skip blank cells in a loop

  1. #1
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Skip blank cells in a loop

    I am converting an inventory from the form:
    Item ID #Small #Medium #Large...
    1 4 5 6
    2 8 9 10

    to

    Item ID/SIZE #Available
    1Small 4
    1Medium 5
    1Large 6
    2Small 8
    ...


    I have code that does this effectively.

    Please Login or Register  to view this content.
    However, if there are blanks in the table, my current code creates items with 0 available. I would like it to skip blanks and only create a new item if there is a non-zero quantity of that size for that item.

  2. #2
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Skip blank cells in a loop

    Try performing a check before continuing to main operation like..
    Please Login or Register  to view this content.
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  3. #3
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Skip blank cells in a loop

    I think you're right that that's the strategy I should use. When I ran that code, it deleted all my data . I think it's offset incorrectly.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Skip blank cells in a loop

    Avoid using ActiveCell.
    Are you trying to loop through a range of non blank rows? It may be easier to resolve it if you could attach a sample.

  5. #5
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Skip blank cells in a loop

    Sample.xlsm

    This is the first macro I've written, so I'm up for learning better techniques. How should I write it to avoid using ActiveCell?

    I attached a sample with made-up data. The first sheet is the before data and the second sheet is my desired result.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Skip blank cells in a loop

    The code is not looping through a range rather, looping through an array. The result is in new sheet created by the code itself.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Skip blank cells in a loop

    Thanks. That works perfectly. I'll spend some time looking through your code to figure out what you did, since it looks like a cleaner way than I took.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Skip blank cells in a loop

    Your first upload the data in to array and then loop through the array. Once the data have been written over to new array (Y), you write it back to the range. It is much faster than looping through a range.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Skip blank cells in a loop

    K64,
    You are welcome!
    Please mark this thread as solved!

+ 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] Skip loop if cells equal same values
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-02-2012, 01:19 PM
  2. How to Skip blank cells SEE PIC
    By zit1343 in forum Excel General
    Replies: 13
    Last Post: 04-12-2012, 05:43 PM
  3. Skip blank cells
    By kenjiventurina in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2012, 02:52 AM
  4. skip blank cells
    By Seroleh in forum Excel General
    Replies: 16
    Last Post: 05-28-2009, 02:21 AM
  5. Skip Blank Cells
    By belly0fdesire in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-08-2006, 02:21 AM

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