+ Reply to Thread
Results 1 to 8 of 8

VBA formula in stead of Countif & OR/AND to get quick and light file

  1. #1
    Registered User
    Join Date
    06-26-2012
    Location
    Hanoi, Vietnam
    MS-Off Ver
    Excel 2003
    Posts
    6

    VBA formula in stead of Countif & OR/AND to get quick and light file

    Hello everyone,

    I attached herewith a file filled with Countif, sum, or, and. I look for a VBA to get lighter file. Because the file in fact will be filled up to 40,000 rows.

    Please anyone can help me.

    Thank you so much.
    Thanh

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: VBA formula in stead of Countif & OR/AND to get quick and light file

    I might be able to help you, but...
    I used a different formula in F30:
    =SUMPRODUCT(COUNTIF(F$1:F$27,$A30:$D30))
    and got some different numbers. Specifically, G30 was a 9 instead of an 8, and I30 was a 2 instead of a 1. Is my assumption on your intended calculation correct, or do you want the same logic you used to get your numbers?

    I understand your first set of data is 40,000 rows. Is it always 40,000?

    Are the columns going to be the same width (i.e. 6) or will they be different? Will the data in columns F:K and S:X be the same or could they be different?

    What about the data set at A30:D34? Is that provided by the user or is it somehow generated from the data above it? Is it always the same as the data in N30:Q34? Is it always 4 columns and/or 5 rows? Is it always 3 rows below the bottom of your top data and does it always start in the first column?

    What is the range of the numbers in the data set? 00 to 99?

    Also, why do you have all the numbers as text? The first thing I would do is convert them all to numbers. Any hard reason why you have them as text?

    Finally, I don't quite understand your need to go to VBA. With 40,000 rows of data, your file will not be light, and the formulas you are using should be fairly quick and efficient (Excel formulas, unless you are doing array formulas, are generally faster than VBA).
    Last edited by Pauleyb; 05-29-2014 at 03:34 PM.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: VBA formula in stead of Countif & OR/AND to get quick and light file

    Since I'll probably be sleeping when you respond, here is some code that works with your specific example. I made many assumptions (always 6 columns, only checking four numbers per row, my calculated results, etc.), but the number of rows can be different, it just expects the numbers to check against (e.g. A30:D34) to be three rows beneath the base data. I added this as a macro to Sheet1.

    Please Login or Register  to view this content.
    Last edited by Pauleyb; 05-29-2014 at 04:27 PM.

  4. #4
    Registered User
    Join Date
    06-26-2012
    Location
    Hanoi, Vietnam
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA formula in stead of Countif & OR/AND to get quick and light file

    Quote Originally Posted by Pauleyb View Post
    Since I'll probably be sleeping when you respond, here is some code that works with your specific example. I made many assumptions (always 6 columns, only checking four numbers per row, my calculated results, etc.), but the number of rows can be different, it just expects the numbers to check against (e.g. A30:D34) to be three rows beneath the base data. I added this as a macro to Sheet1.

    Please Login or Register  to view this content.
    Thank you for your help.
    It seems that I was not good at previous explanation. Now I enclose a new file that separate into 2 sheets. You can see the formula will give result when the data updated daily (the formula is filled at all cells of the row)

    And now I make clear to your questions:

    1. I understand your first set of data is 40,000 rows. Is it always 40,000?
    - It depend on the weight of file. It can be 40,000 or 30,000 but

    2. Are the columns going to be the same width (i.e. 6) or will they be different? Will the data in columns F:K and S:X be the same or could they be different?
    - The columns are updated with data daily

    3. What about the data set at A30:D34? Is that provided by the user or is it somehow generated from the data above it?
    - It is provided by user.

    4. Is it always the same as the data in N30:Q34? Is it always 4 columns and/or 5 rows? Is it always 3 rows below the bottom of your top data and does it always start in the first column?
    - It is always 4 columns.

    9. What is the range of the numbers in the data set? 00 to 99?
    - Yes, it is from 00 to 99

    10. Also, why do you have all the numbers as text? The first thing I would do is convert them all to numbers. Any hard reason why you have them as text?
    - Because I want to have 0 in: 00, 01, 02,..09

    11. Finally, I don't quite understand your need to go to VBA. With 40,000 rows of data, your file will not be light, and the formulas you are using should be fairly quick and efficient (Excel formulas, unless you are doing array formulas, are generally faster than VBA).
    - Because with Excel formulas, the file is up to 600Mb, and I have to wait for minutes to get result.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: VBA formula in stead of Countif & OR/AND to get quick and light file

    Okay, so is the code provided enough to get you started and you can modify to your specifics?

    Just some other comments:
    Are the columns going to be the same width (i.e. 6) or will they be different? Will the data in columns F:K and S:X be the same or could they be different?
    - The columns are updated with data daily
    I'm still not sure if the 'input' data is always 6 columns. Is a new column added every day? If so, would you only need to calculate the AND/OR for the last column?

    - Because I want to have 0 in: 00, 01, 02,..09
    I would still change them to numbers instead of text. Then just use the custom format of '00'. It makes calculations so much easier.

    If you still need help, I can work on it again on Monday.

  6. #6
    Registered User
    Join Date
    06-26-2012
    Location
    Hanoi, Vietnam
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA formula in stead of Countif & OR/AND to get quick and light file

    Quote Originally Posted by Pauleyb View Post
    Okay, so is the code provided enough to get you started and you can modify to your specifics?

    Just some other comments:

    I'm still not sure if the 'input' data is always 6 columns. Is a new column added every day? If so, would you only need to calculate the AND/OR for the last column?


    I would still change them to numbers instead of text. Then just use the custom format of '00'. It makes calculations so much easier.

    If you still need help, I can work on it again on Monday.
    Thank you for your help.
    For the question:
    "I'm still not sure if the 'input' data is always 6 columns. Is a new column added every day? If so, would you only need to calculate the AND/OR for the last column?"
    My answer is the input is filled daily and it will be more than 6 columns and will be up to the last (IV) column

  7. #7
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: VBA formula in stead of Countif & OR/AND to get quick and light file

    Create a Module for this spreadsheet and put this code in it:
    Please Login or Register  to view this content.
    Last edited by Pauleyb; 06-04-2014 at 04:35 PM. Reason: Added Application.ScreenUpdating lines

  8. #8
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: VBA formula in stead of Countif & OR/AND to get quick and light file

    Thanks for the rep bump. Always nice to be acknowledged. Also, I forgot in the code to add:
    Application.ScreenUpdating = False
    at the top of the code and then
    Application.ScreenUpdating = True
    at the end.

    That should speed it up quite a bit. I updated the code above to include.

+ 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] Quick Countif and And function help
    By FootyMan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-02-2013, 06:05 AM
  2. Display expanded formula in cell in stead of cell references
    By vnr2583 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-24-2013, 10:06 PM
  3. Traffic light Formula not working
    By TonydeBurgh in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-15-2013, 02:17 PM
  4. [SOLVED] Excel showing a row of ##### in stead of dollars, but when
    By Jammie in forum Excel General
    Replies: 2
    Last Post: 04-03-2006, 02:30 PM
  5. quick way to copy-paste a formula linked to cells in another file
    By iniakupake in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-25-2005, 10:56 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