Solved

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

Posted on 2014-07-23
13
183 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 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

Technology Partners: 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!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

739 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