Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-30-2018, 04:45 AM
SailorJerry7030 SailorJerry7030 is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2016
Novice
Sum Frequencies in VBA in Excel
 
Join Date: Apr 2018
Posts: 7
SailorJerry7030 is on a distinguished road
Default Sum Frequencies in VBA in Excel

Good Morning All!



I hope I have an easy one for you this morning. I've got about 96k rows of policy numbers and 12 columns starting in column B (Jan-Dec). If a policyholder called within that month it displays how many times they called. I'm not concerned with how many calls they made, only if there is a value > 0 within that cell. The goal here is to sum the clusters of consecutive months they called in. If they call in just in January but not in February, I don't care. If they call in January and February, but not March, that would be considered 1 cluster. If they called in January, February, March, not in April, not in May, called in June, not called in July, called in August, called in September, didn't call us the rest of the year, the sum of clusters would be 2 (Jan-Mar) and (Aug-Sept), don't care about the 1 off month of June where they called since it's not a cluster. I've been trying to incorporate code similar to "=SUM(--((FREQUENCY(IF(A2:H2>=50, COLUMN(A2:H2)),IF(A2:H2<50,COLUMN(A2:H2))))>=3))" granted this series of code is for a completely different project unrelated, but I feel like it could be applicable by changing the cells and values (50 and 3).

I hope this goal makes sense and someone can help. If you need anymore information, let me know. The simpler the better.
Reply With Quote
  #2  
Old 04-30-2018, 07:08 AM
ArviLaanemets ArviLaanemets is offline Sum Frequencies in VBA in Excel Windows 8 Sum Frequencies in VBA in Excel Office 2016
Expert
 
Join Date: May 2017
Posts: 932
ArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant future
Default

Having Policy in column A, and months in columns B:M
Code:
=AND(SUM(B2)>0,C2>0,D2=0)+AND(SUM(C2)>0,D2>0,E2=0)+AND(SUM(D2)>0,E2>0,F2=0)+AND(SUM(E2)>0,F2>0,G2=0)+AND(SUM(F2)>0,G2>0,H2=0)+AND(SUM(G2)>0,H2>0,I2=0)+AND(SUM(H2)>0,I2>0,J2=0)+AND(SUM(I2)>0,J2>0,K2=0)+AND(SUM(J2)>0,K2>0,L2=0)+AND(SUM(K2)>0,L2>0,M2=0)+AND(SUM(L2)>0,M2>0)
Enter the formula into cell N2, and copy down.
Reply With Quote
  #3  
Old 04-30-2018, 07:10 AM
SailorJerry7030 SailorJerry7030 is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2016
Novice
Sum Frequencies in VBA in Excel
 
Join Date: Apr 2018
Posts: 7
SailorJerry7030 is on a distinguished road
Default

Quote:
Originally Posted by ArviLaanemets View Post
Having Policy in column A, and months in columns B:M
Code:
=AND(SUM(B2)>0,C2>0,D2=0)+AND(SUM(C2)>0,D2>0,E2=0)+AND(SUM(D2)>0,E2>0,F2=0)+AND(SUM(E2)>0,F2>0,G2=0)+AND(SUM(F2)>0,G2>0,H2=0)+AND(SUM(G2)>0,H2>0,I2=0)+AND(SUM(H2)>0,I2>0,J2=0)+AND(SUM(I2)>0,J2>0,K2=0)+AND(SUM(J2)>0,K2>0,L2=0)+AND(SUM(K2)>0,L2>0,M2=0)+AND(SUM(L2)>0,M2>0)
Enter the formula into cell N2, and copy down.
Works like a charm butttttttt is there a way to put this into VBA code? I only ask because this is going to apply to 96,000 records
Reply With Quote
  #4  
Old 04-30-2018, 08:08 AM
ArviLaanemets ArviLaanemets is offline Sum Frequencies in VBA in Excel Windows 8 Sum Frequencies in VBA in Excel Office 2016
Expert
 
Join Date: May 2017
Posts: 932
ArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant future
Default

Quote:
Originally Posted by SailorJerry7030 View Post
is there a way to put this into VBA code? I only ask because this is going to apply to 96,000 records
Is the formula slowing the worksheet down? I ask because this is simple arithmetical formula which needs not much resources.

When yes, then of-course you can write a VBA procedure, which counts the number of rows in UsedRange, and processes then every datarow in your table, calcualtes same formula in VBA (you have to remember, that in VBA FALSE is 0 like in worksheet, but TRUE converts to -1, so you hafe to multiply the result with -1) for every row, and writes the result into proper column in your table. You can run the procedure from button on worksheet, or you can create a shortcut key combination to run it.

I myself don't have Office available for today and tomorrow.
Reply With Quote
  #5  
Old 04-30-2018, 08:09 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,920
Pecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond repute
Default

Perhaps post a sample sheet with some data and expected results? ( Go advanced - Manage attachments)
__________________
Using O365 v2503 - Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #6  
Old 04-30-2018, 08:16 AM
SailorJerry7030 SailorJerry7030 is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2016
Novice
Sum Frequencies in VBA in Excel
 
Join Date: Apr 2018
Posts: 7
SailorJerry7030 is on a distinguished road
Default

Quote:
Originally Posted by Pecoflyer View Post
Perhaps post a sample sheet with some data and expected results? ( Go advanced - Manage attachments)
No problem! Here is the test data. Test 1, Test 2, etc will be policy #'s and column Q is where I'd like the sum of the clusters to be placed. The Excel Code that ArviLaanemets provided works perfectly and gives the correct results in column S. However, I'm trying to use code in VBA to achieve these results as it will be for a larger data set.
Attached Images
File Type: png sample.PNG (16.2 KB, 13 views)
Reply With Quote
  #7  
Old 04-30-2018, 09:25 AM
NoSparks NoSparks is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Oh-no, Pecoflyer's going to delete everything above until you supply links to your cross posts
Reply With Quote
  #8  
Old 04-30-2018, 09:27 AM
SailorJerry7030 SailorJerry7030 is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2016
Novice
Sum Frequencies in VBA in Excel
 
Join Date: Apr 2018
Posts: 7
SailorJerry7030 is on a distinguished road
Default

Quote:
Originally Posted by NoSparks View Post
Oh-no, Pecoflyer's going to delete everything above until you supply links to your cross posts
Didn't even think about that haha umm..I think I only made 2 other posts, let's see...

https://www.ozgrid.com/forum/forum/h...uencies-in-vba

https://www.mrexcel.com/forum/excel-...ithin-vba.html

better?
Reply With Quote
  #9  
Old 04-30-2018, 09:51 AM
NoSparks NoSparks is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Using NBVC's formula, adjusted for the columns you actually want, and the sample workbook you posted over there....see if this works

Code:
Sub Clusters()
Dim lr As Long
With Sheets("Sheet3")
    lr = .Cells(2, "A").End(xlDown).Row
    .Range("Q2").FormulaArray = "=SUM(--((FREQUENCY(IF(B2:M2>0, COLUMN(B2:M2)),IF(B2:M2=0,COLUMN(B2:M2))))>1))"
    .Range("Q2").AutoFill Destination:=Range("Q2:Q" & lr)
End With
End Sub
Reply With Quote
  #10  
Old 04-30-2018, 10:02 AM
SailorJerry7030 SailorJerry7030 is offline Sum Frequencies in VBA in Excel Windows 7 64bit Sum Frequencies in VBA in Excel Office 2016
Novice
Sum Frequencies in VBA in Excel
 
Join Date: Apr 2018
Posts: 7
SailorJerry7030 is on a distinguished road
Default

Quote:
Originally Posted by NoSparks View Post
Using NBVC's formula, adjusted for the columns you actually want, and the sample workbook you posted over there....see if this works

Code:
Sub Clusters()
Dim lr As Long
With Sheets("Sheet3")
    lr = .Cells(2, "A").End(xlDown).Row
    .Range("Q2").FormulaArray = "=SUM(--((FREQUENCY(IF(B2:M2>0, COLUMN(B2:M2)),IF(B2:M2=0,COLUMN(B2:M2))))>1))"
    .Range("Q2").AutoFill Destination:=Range("Q2:Q" & lr)
End With
End Sub
Perfect! I was having difficulty fitting that formula into the code, but this does it!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word & Excel 2010 - Best Options To Auto Insert MySQL & Excel Data? Hoser Word 1 03-17-2017 03:47 PM
Embeding Excel Docs in Word - Receiving Memory Error Message if Excel is open kdash Word 0 05-06-2015 09:38 AM
Sum Frequencies in VBA in Excel How To Open an Macro From 2003 Excel in 2013 Excel Spread Sheet? ADubin Excel Programming 3 02-08-2015 04:57 AM
Sum Frequencies in VBA in Excel [Excel 2007] Building Power Point Slides from data in an Excel Table bremen22 Excel Programming 1 08-07-2013 11:01 AM
Sum Frequencies in VBA in Excel Excel 2011 can't open old Excel 98 or Excel X files FLJohnson Excel 8 05-09-2012 11:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft