Solved

Same number of instances in two columns?

Posted on 2013-05-29
7
204 Views
Last Modified: 2013-05-30
Looking for a macro that I can run that will tell me the number of instances that the number one is in column C and the number of instances that the number one is in column AG.  These should match.  If 6 in column C there should be 6 in column AG.

Ideally a dialog box that shows the results of each would be nice.  Thanks -R-
0
Comment
Question by:RWayneH
  • 4
  • 3
7 Comments
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 39205376
Here it is try this code

Sub CountCAG()
Dim WS As Worksheet
Dim MaxRow As Long, I As Long
Dim CountC As Long, CountAG As Long

Set WS = ActiveSheet
MaxRow = WS.Range("C" & WS.Rows.Count).End(xlUp).Row

For I = 1 To MaxRow
    If WS.Cells(I, "C").Value = 1 Then
        CountC = CountC + 1
    End If
    
    If WS.Cells(I, "AG").Value = 1 Then
        CountAG = CountAG + 1
    End If
Next I

MsgBox ("Results of Counting Cells containing 1:" & Chr(10) & "Col C: " & Chr(9) & CountC & Chr(10) & "Col AG: " & Chr(9) & CountAG)

End Sub

Open in new window


Rgds/gowflow
0
 

Author Closing Comment

by:RWayneH
ID: 39205432
EXCELent!!  Thanks -R-
0
 

Author Comment

by:RWayneH
ID: 39205534
Hold the bus...  Do I need to reformat the columns so it recongizes all the ones?  It is failing on the attached sheet.  Please advise and thanks. -R-
CountCAG-Error.xlsx
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:RWayneH
ID: 39205544
I noticed that AG is not the same length as C.  They can have different row amount in each column.  Is that a possible issue? -R-
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39206801
Well I incorporated the macro to your workbook and renamed it as .xlsm and changed the maximum rows as seem it was the problem. Check this version and note that in your data Col AG has more rows than Col C maybe that is your problem. Go down in your data and you will see that Col C stops at row 66 and then Col AG keeps on till row 172 maybe this is your problem ??? Anyhow the previous version would compare only the first 66 rows now it goes far beyond that to ensure no rows are missed.

Let me know. Delay in reply due to diffrent time zones.
gowflow
CountCAG-Error.xlsm
0
 

Author Comment

by:RWayneH
ID: 39207484
Now it is good.  Thanks for the additional edit.  -R-
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39207516
your welcome pls feel free to ask for me case u need it more adapted to what you want
gowflow
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now