Solved

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

Posted on 2014-07-23
13
178 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 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

777 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