How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask R.R. Jha Your Own Question

R.R. Jha
R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5471
Experience:  B.Tech
Type Your Homework Question Here...
R.R. Jha is online now
A new question is answered every 9 seconds

i have to write a VBA code to realize the countifs to corresponding

This answer was rated:

i have to write a VBA code to realize the countifs to corresponding resutls.
ColA ColB
1 8
1 3
2 3
2 4
2 8
2 4
3 5
3 6
4 7
4 8
5 8
5 5
5 4
6 5
6 6
6 7
with a result as count only if ColB >5
ColA ColB
1 1
2 1
3 2
4 2
5 2
6 3

I'd be glad to help. I'll work it out and get back to you asap.

Try this code. Based on output, I assumed you're looking for >=5 rather than >5. It puts result into column D and E.

Sub myCount()
Dim min As Double, max As Double
min = Application.WorksheetFunction.min(Columns(1))
max = Application.WorksheetFunction.max(Columns(1))
For i = min To max
range("D" & (i - min + 1)).Value = i
range("E" & (i - min + 1)).Value = Application.WorksheetFunction.CountIfs(Columns(1), i, Columns(2), ">=5")
End Sub

Customer: replied 3 years ago.

Can I put the result in a new workbook?

How to add this code

Yes, we can. I'll modify the code and let you know.

You need to spend $3 to view this post. Add Funds to your account and buy credits.
R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5471
Experience: B.Tech
R.R. Jha and 6 other Homework Specialists are ready to help you
Customer: replied 3 years ago.

Sorry but I think I explain it wrong, I need to make the result in another worksheet instead of wookbook.

Ok, I'll modify it.
Customer: replied 3 years ago.

and the result seems to be not correct. When I tried this code, the first column of the result turn to be numbers, but in the real data, the first column of the results should be the names not number. Because the original dataset's first column contains people's name instead of numbers.

Ok, I'll change it to work for strings
Here you go.

Sub myCount()
Set ws1 = ActiveSheet
Set ws2 = Worksheets.Add(After:=ws1)
ws1.range("A1", ws1.range("A65536").End(xlUp)).Copy ws2.range("A1")
ws2.range("A1", ws2.range("A65536").End(xlUp)).RemoveDuplicates 1, xlNo
For Each c In ws2.range("A1", ws2.range("A65532").End(xlUp)).Cells
Count = Application.WorksheetFunction.CountIfs(ws1.Columns(1), c, ws1.Columns(2), ">=5")
ws2.range("B" & c.Row).Value = Count
End Sub
Customer: replied 3 years ago.

Hello, its me agian. I am wondering how to add other countifs accourding to the results that we developed in the new worksheets from other columns in the original worksheets. Like if I have column d, e, f, g as well,

and i want to count the numbers of data in each column according to the Column A in ws2

Just change formula for count.

Count = Application.WorksheetFunction.CountIfs(ws1.Columns(1), c, ws1.Columns(2), ">=5")

In above formula, Columns(2) means it's counting values in column B. For counting values in column C change it to Columns(3), for D change it to Columns(4) and so on.

Also, change the line just below that to put other counts in separate column.

ws2.range("B" & c.Row).Value = Count

If you're counting values in column C, change "B" to "C" and so on.


JustAnswer in the News:

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

What Customers are Saying:

  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Previous | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX

Meet The Experts:

  • LogicPro



    Satisfied Customers:

    Expert in Java C++ C C# VB Javascript Design SQL HTML
< Last | Next >
  • LogicPro's Avatar



    Satisfied Customers:

    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany


    Satisfied Customers:

    More than 5000 online tutoring sessions.
  • Linda_us's Avatar


    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    Post Graduate Diploma in Management (MBA)
  • Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    Experience with chartered accountancy
  • Bizhelp's Avatar



    Satisfied Customers:

    Bachelors Degree and CPA with Accounting work experience
  • Seanna's Avatar



    Satisfied Customers:

    3,000+ satisfied customers, all topics, A+ work

Related Homework Questions