+ Reply to Thread
Results 1 to 9 of 9

Slow process to replace blocks of zeros with null

  1. #1
    Registered User
    Join Date
    09-22-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Post Slow process to replace blocks of zeros with null

    I have a woksheet that has has 61 Columns.

    Column A has a date.
    Column B through Column G has 6 different product information for the same entity.
    Column H through Column M has 6 differnet product information for the same entity, etc.

    I want to find the first non-zero in column B, then in all previous rows above the non-zero I want to have the zeros replaced with an empty cell for the 6 columns of the same entity.

    Currently I have the code below but it takes a long time to execute. Is there a way to do this wtih an array and how?

    Any help is appreciated, I am definately over my head with my limited knowledge.


    Please Login or Register  to view this content.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Slow process to replace blocks of zeros with null

    Can you post your workbook?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    09-22-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Slow process to replace blocks of zeros with null

    Sorry for the delay. I tired attaching the file but was told it was too big. I have put it in a zip file. If that does not work for you, then I will eliminate columns and rows. My first time on this board and trying to attach a file so hopefully I did it correctly.

    The code is not in the file.

    Thank you so much for your help. It is appreciated
    Attached Files Attached Files

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Slow process to replace blocks of zeros with null

    ok help me understang this a little more. So in Column B the first Not empty cell greater then 0 is row 92. Now heres where Im lost. So everything above row 92 should be cleared out From Column B to G?

  5. #5
    Registered User
    Join Date
    09-22-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Slow process to replace blocks of zeros with null

    Thanks Mike!

    Yes, I want in Column B through G to have Rows 2-91 to have a blank cell if there is a zero. If there is not a zero, the data would remain. (For example in column F row 87-91 there is data, so those cells would not change).

    Then in Columns H through M, rows 2-1244, zero would be replaced by an empty cell, Columns N through S rows 2-197, zeros would be replaced by an empty cell.

    The code I posted does this but since it looks at each cell, the process is slow. I am hoping for a more effecient way.

    This data is being used in a graph which is why the zeros need to be empty so they are not plotted until they actually begin.

    Again, I appreciate your guidance.

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Slow process to replace blocks of zeros with null

    Give this a try

    Please Login or Register  to view this content.
    Last edited by mike7952; 11-27-2012 at 09:59 AM.

  7. #7
    Registered User
    Join Date
    09-22-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Thumbs up Re: Slow process to replace blocks of zeros with null

    Thank youi! I did a quick test and it worked so fast. Just what I needed.

    Can you explain what you did by the steps, so I can understand a little bit better. I understand that the process is doing everything in an array and then putting the results in the new workbook. What I don't understand is how the range is being assigned. For example what does the double i exactly do? I know that is an extra request but I am basically self taught and I would love to get over this hurdle on using arrays.

    But no matter if you can take that extra time or not, you really helped. Thank you.

    Ari

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Slow process to replace blocks of zeros with null

    I dont have much time now but here's another way. Its almost the same as the array. But maybe it will give you a better understanding. It clears the column at all once instead of clearing every cell, cell by cell.

    Please Login or Register  to view this content.
    And heres the array code with replaced variables. Maybe this will help
    Please Login or Register  to view this content.
    Last edited by mike7952; 11-27-2012 at 03:09 PM.

  9. #9
    Registered User
    Join Date
    09-22-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Slow process to replace blocks of zeros with null

    Thank you again. Breaking the code up as you did was helpful.

    Ari

+ 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