运行时错误6'溢出',其中变量声明为整数

时间:2016-09-26 07:56:04

标签: excel vba excel-vba

存在运行时错误6'溢出',其中变量声明为整数。

Sub yahoo()
  Dim n As Integer
  Range("A:a").AutoFilter Field:=1, Criteria1:="*yahoo*"
  n = Range("a:a").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Count
  Range("c1") = n
End Sub

1 个答案:

答案 0 :(得分:0)

将整数替换为长整数(有关VBA数据类型的更多内容:https://msdn.microsoft.com/en-us/library/47zceaw7.aspx

Sub yahoo()
  Dim n As Long
  Range("A:a").AutoFilter Field:=1, Criteria1:="*yahoo*"
  n = Range("a:a").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Count
  Range("c1") = n
End Sub