+ Reply to Thread
Results 1 to 6 of 6

help with turning this forumla into a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    help with turning this forumla into a macro

    Hi Everyone,

    I am currently working with a huge excel spreadsheet (650000+ lines) in which I'm trying run the following formula to count the number of unique values (customer code + product brand combination):

    =IF(ISNUMBER(SUM(1/COUNTIF($V$2:$V$158726,$V$2:$V$158726))),SUM(1/COUNTIF($V$2:$V$158726,$V$2:$V$158726)),"")

    With one column taking.. hours to calculate (there are 9 columns altogether to calculate), I am looking to get some help to translate/put this into a macro.

    Also, if I do run this formula as a macro, does it actually speed up the calculating time at all?

    Any help would be greatly appreciated!

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: help with turning this forumla into a macro

    Does this do what you're looking for?

    Sub test()
    Dim i As Integer, numu As Integer
    numu = 0
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    For i = 2 To UsedRange.Rows.Count
    If Range("V" & i).Value = "" Then GoTo nxt
    If WorksheetFunction.CountIf(Range("V:V"), Range("V" & i).Value) < 2 Then numu = numu + 1
    nxt:
    Next i
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    
    MsgBox numu & " unique values in column V"
    End Sub
    Please click the * below if this helps
    Please click the * below if this helps

  3. #3
    Registered User
    Join Date
    06-19-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: help with turning this forumla into a macro

    Hi JasperD,

    Thank you for your reply!

    Got the chance to test the code out today, and whilst the code works, it's not 100% what I am looking for.

    I'm actually wanting to pivot all the information at the very end, so instead of a pop up box with the number of unique values, I'm hoping to get the calculations visible in the next column.

    I would be great to get some further advice from you!

  4. #4
    Forum Contributor
    Join Date
    07-10-2012
    Location
    Bangladesh
    MS-Off Ver
    Excel 2007
    Posts
    129

    Re: help with turning this forumla into a macro

    i am using macro for vlookuo and sumif fuction around 400000 cells it took half and hour

    and you are calculating 158726 into 9 column

    it will take time

    or just increase RAM and PROCESSOR capacity

  5. #5
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: help with turning this forumla into a macro

    what do you actually want in the next column then?
    Just the number of times the value is in that column?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646
    If you want to pivot why not use a pivot table?

    Mind you with that amount of data I would probably think about using a database.

    Perhaps not for the calculations but for storage at least.
    Last edited by Norie; 06-21-2013 at 08:24 AM.
    If posting code please use code tags, see here.

+ 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