+ Reply to Thread
Results 1 to 3 of 3

VBA code that lookups, stores, and counts unique numbers

  1. #1
    Registered User
    Join Date
    12-22-2011
    Location
    Washington, United States
    MS-Off Ver
    Excel 2003
    Posts
    15

    VBA code that lookups, stores, and counts unique numbers

    Hi, I'm new to the forum and I'm new to coding in VBA. I'm working on a file for work and I'm stumped on how to write the middle steps.

    I'm using a raw data spreadsheet from "Workbook A" that generates daily and I need to automate the calculations for the data. Some calculations are in "Workbook A" and "Workbook B".

    I have a nested IF function in "Workbook A" that determines if the date in Col H is passed due, has an upcoming due date, or is due much later. The function returns a value of 1 (passed due), 2 (upcoming due date), or 0 (due much later) and stores it the corresponding cell in Col S.

    I also have a function in "Workbook B" that gives me what I want from Col N of "Workbook A": =SUMPRODUCT(--(FREQUENCY([Workbook_A.xls]Sheet1!$N:$N,[Workbook_A.xls]Sheet1!$N:$N)>0)). This function returns a count of all the unique items stored in Col N of "Workbook A".

    What I need is a function or code (probably code) that will do this:
    For cells in "Workbook A",Col S that = 1, look up their corresponding identity in Col N, store the identities in an array, and count the number of unique items in that array. Return the count value in Cell A1 of "Workbook B".

    The same thing would be repeated for items in Col S that = 2 but return the count value in Cell A2 of "Workbook B".

    I suspect VLookup would be used (or the VBA-equivalent), but I don't know if that can store the value in an array. If necessary, the columns can be re-arranged so Col S becomes Col A so a database function can be used.

    Any help would be greatly appreciated! Thanks in advance!
    Last edited by shadyferret; 12-22-2011 at 04:04 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Assistance needed for VBA code that lookups, stores, and counts unique numbers

    Hi

    On a cursory examination, I'm thinking that this could be done with functions using helper columns, or code.

    Can you attach an example workbook for us to review, and show the output you would expect to get for the example data.

    rylo

  3. #3
    Registered User
    Join Date
    12-22-2011
    Location
    Washington, United States
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Assistance needed for VBA code that lookups, stores, and counts unique numbers

    Yes, I can. Sorry about the delay - the day after this I found myself in one of the few CA locations without internet and I was there for 2 weeks! That wasn't expected.

    I'm doing this across two different work books because I will be doing a lot more changes to Workbook_A after this, but it doesn't impact my question. I've posted only Workbook_A, and I've modified Workbook_A to remove some of the data. All the data I changed isn't involved in the calculations anyways.

    Workbook_B can look like anything, honestly.


    Thanks for looking at this!
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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