• 100% Satisfaction Guarantee

R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5471
Experience:  B.Tech
20870358
R.R. Jha is online now

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

### Resolved Question:

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
Submitted: 3 years ago.
Category: Homework
Expert:  R.R. Jha replied 3 years ago.
Hi,

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

Thanks
Expert:  R.R. Jha replied 3 years ago.
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")
Next
End Sub

Thanks
Customer: replied 3 years ago.

Can I put the result in a new workbook?

Expert:  R.R. Jha replied 3 years ago.
Yes, we can. I'll modify the code and let you know.
Expert:  R.R. Jha replied 3 years ago.

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

Expert:  R.R. Jha replied 3 years ago.
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.

Expert:  R.R. Jha replied 3 years ago.
Ok, I'll change it to work for strings
Expert:  R.R. Jha replied 3 years ago.
Here you go.

Sub myCount()
Set ws1 = ActiveSheet
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
Next
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

Expert:  R.R. Jha replied 3 years ago.
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.

Thanks

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... Justanswer.com.
...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

• ### LogicPro

#### Satisfied Customers:

4925
Expert in Java C++ C C# VB Javascript Design SQL HTML
< Last | Next >

### LogicPro

#### Satisfied Customers:

4925
Expert in Java C++ C C# VB Javascript Design SQL HTML

### Manal Elkhoshkhany

#### Satisfied Customers:

4538
More than 5000 online tutoring sessions.

### Linda_us

#### Satisfied Customers:

3138
Post Graduate Diploma in Management (MBA)

### Chris M.

#### Satisfied Customers:

2602
Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)

### F. Naz

#### Satisfied Customers:

2126
Experience with chartered accountancy

### Bizhelp

#### Satisfied Customers:

1887
Bachelors Degree and CPA with Accounting work experience