Solved

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

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

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

717 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