Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3566|回复: 7

[已解决]怎样统计指定起始行号之间的数据(VBA中用Countif)?

[复制链接]
发表于 2012-11-2 09:45 | 显示全部楼层 |阅读模式
请高手帮忙,看看这个 Countif在VBA中的运用.rar (7.45 KB, 下载次数: 28)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-11-2 09:54 | 显示全部楼层
  1. Sub total()
  2.     Dim x, y As Integer
  3.     x = Range("d2")
  4.     y = Range("d3")
  5.    
  6.     With Worksheets("sheet1")
  7.         MsgBox Application.WorksheetFunction.CountIf(.Range(.Cells(x, 3), .Cells(y, 3)), "A")
  8.     End With
  9. End Sub
复制代码
回复

使用道具 举报

发表于 2012-11-2 09:56 | 显示全部楼层
  1. Sub total()
  2. Dim x, y As Integer
  3. x = Range("d2")
  4. y = Range("d3")

  5. Range("b4") = Application.WorksheetFunction.CountIf(Sheets("sheet1").Range(Sheets("sheet1").Cells(x, 3), Sheets("sheet1").Cells(y, 3)), "A")


  6. End Sub
复制代码
回复

使用道具 举报

发表于 2012-11-2 09:57 | 显示全部楼层    本楼为最佳答案   
  1. Sub total()
  2.     Dim x, y As Integer
  3.     x = Range("d2")
  4.     y = Range("d3")
  5.     With Sheets("sheet1")
  6.         Range("b4") = Application.WorksheetFunction.CountIf(.Range(.Cells(x, 3), .Cells(y, 3)), "A")
  7.     End With
  8. End Sub
复制代码
回复

使用道具 举报

发表于 2012-11-2 09:57 | 显示全部楼层
  1. Sub total()
  2. Dim x, y As Integer
  3. x = Range("d2").Value
  4. y = Range("d3").Value
  5. Range("b4") = Application.WorksheetFunction.CountIf(Sheet1.Range("c" & x & ":c" & y), "A")
  6. End Sub
复制代码
改成这样试试

点评

这样也不错。  发表于 2012-11-2 09:59
回复

使用道具 举报

发表于 2012-11-2 09:58 | 显示全部楼层
用4楼的代码吧,简单明了。
加N多前缀太麻烦了。
回复

使用道具 举报

发表于 2012-11-2 10:01 | 显示全部楼层
本帖最后由 huoxieshen 于 2012-11-2 10:03 编辑
  1. Sub total()
  2. Dim x As Integer, y As Integer, r As Long, arr(), brr(1 To 60000, 1 To 1)
  3. x = Range("d2").Value
  4. y = Range("d3").Value
  5. r = Cells(Rows.Count, 1).End(3).Row
  6. arr = Range("a4:a" & r).Value
  7. With Sheet1
  8.   For i = 1 To r - 3
  9.     brr(i, 1) = Application.WorksheetFunction.CountIf(.Range("c" & x & ":c" & y), arr(i, 1))
  10.   Next
  11. End With
  12. Range("b4:b65536").ClearContents
  13. Range("b4").Resize(r - 3, 1) = brr
  14. End Sub
复制代码
看看这样可以不???
回复

使用道具 举报

 楼主| 发表于 2012-11-4 11:16 | 显示全部楼层
真心感谢各位,帮我解决了困我好几天的问题.再次谢谢!答案都好,也不好设最佳了,要不设一个其他的有意见呀
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-19 21:05 , Processed in 0.347356 second(s), 17 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表