?
Solved

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

Posted on 2014-07-23
13
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 4

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

762 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