Solved

Count the number of times this is in a column and put result in cell

Posted on 2014-07-23
13
175 Views
Last Modified: 2014-07-23
How do I do the following in VBA.  I can explain in English what I would like it to do.

Goto column O (letter not zero) of the active sheet, and count the number of times the letter “S” is there.  Place the result in cell A6 even if it is zero.
Then
Goto column Q and tell if there is a value of “WD” in that column?  If so, place that value in cell A7, if does not exist, leave A7 blank.
0
Comment
Question by:RWayneH
13 Comments
 
LVL 3

Expert Comment

by:Mitchell Milligan
ID: 40214688
Maybe using the CountIF in Excel is a good place to start looking?  If it is Excel, it has a built in feature for this called the =countif command, and then set the range to be counted.
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 40214704
Mitchell is correct, I think author  can search a word of "countif Excel VBA" in internet, there is a lot tutorial  as following sites , and  he  will get it finally
http://www.techonthenet.com/excel/formulas/countif.php

Duncan
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40214706
Agreeing with Mitchell.  Based on the description of the data, it sounds like the entire cell value with either be "S" (for column O) or "WD" (in column Q).  In this case, the following formulas could be inserted in A6 and A7:

A6: =COUNTIF(O:O,"S")
A7: =IF(COUNTIF(Q:Q,"WD")=0,"",COUNTIF(Q:Q,"WD"))

However, if you're looking for occurrences of either value within cells (i.e., part of a larger string of characters), then you'll need different formulas.

Regards,
-Glenn
0
 

Author Comment

by:RWayneH
ID: 40214913
ok.. let me throw this around a bit and see if I can get the results to popular within my For Selection loop.
0
 

Author Comment

by:RWayneH
ID: 40214924
for some reason I have an "S" in column O that it is not seeing.  Returning 0 ??  and there is a WD in column Q and the result is blank??  Looks like the formulas are not returning the proper result?  What am I doing wrg?
DoesColHaveLetterS.xlsx
0
 

Author Comment

by:RWayneH
ID: 40214939
If there is a instance of WD in column Q, it some return the value of "WD" to that cell.  No matter how many times it is there.
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.

 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40214977
RWayneH,
This is because the values in column O and Q are not trimmed; there are trailing spaces after all values (six characters in column O; nine in column Q).

Change the formulas as follows to account for this:
A6:  =COUNTIF(O:O,"S *")  (<--note extra space after the S!)
A7:  =IF(COUNTIF(Q:Q,"WD*")=0,"",COUNTIF(Q:Q,"WD*"))

Regards,
-Glenn
0
 

Author Comment

by:RWayneH
ID: 40214997
How does the formula in A7 chg if I want the result to equal WD?  It is giving me a number.  (original req)
0
 

Author Comment

by:RWayneH
ID: 40215002
Nevermind got it..  Looks like this is going to work!!
0
 

Author Comment

by:RWayneH
ID: 40215010
Opps not sure if it is working....  the rule for column Q is that the value WD has to exist anywhere in Q.  We are not counting that column..  If it is there, place WD in A7, if not leave it blank.
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40215015
I apologize; I didn't read your original instruction properly.  Change the formula for A7 to this:
=IF(COUNTIF(Q:Q,"WD*")=0,"","WD")
0
 

Author Closing Comment

by:RWayneH
ID: 40215056
Thanks works great!!
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40215059
You're welcome.  Sorry about the oversight on your original request.
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

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

867 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

21 Experts available now in Live!

Get 1:1 Help Now