作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在处理一些 VBA 代码,我得到了一个
Argument not optional
Sub Finding_number ()
的第一次迭代中卡住了这让我感到困惑。我没有向该 Sub 传递任何参数或从该 Sub 传递任何参数,那么为什么会出现错误?
Sub Pedal_Actuations_per_hour()
Dim counter As Integer
Dim average_actuations As Single
counter = 1
Do While IsEmpty(ActiveCell.Value) = False
Finding_number
average_actuations = (average_actuations + Pedal_actuations()) / counter
counter = counter + 1
Loop
Range("J2").Value = average_actuations
End Sub
Sub Finding_number()
Dim index As Integer
index = 1
Range("E2").Select
Do While index = 1
If ActiveCell.Value = 121 Then
index = 0
End If
Range.Offset (1)
Loop
End Sub
Function Pedal_actuations() As Integer
Dim time_sum As Single
Dim index As Integer
index = 1
time_sum = 0
Do While time_sum < 1
If IsEmpty(ActiveCell.Value) = 0 Then
date_number = Int(ActiveCell(, -2).Value)
ActiveCell(, 6).Value = ActiveCell(, -2).Value - date_number
ActiveCell(, 7).Value = Abs(ActiveCell(, 6).Value - ActiveCell(2, 6)) *24
Else
index = 0
End If
Pedal_actuations = Pedal_actuations + 1
time_sum = time_sum + ActiveCell(, 7).Value
Loop
End Function
最佳答案
最好避免使用 Select
, ActiveCell
, ETC...
而是使用引用对象作为 Sheets
和 Range
s。
Sub Finding_number()
Dim index As Integer
index = 1
Dim Rng As Range
Set Rng = Range("E2")
Do While index = 1
If Rng.Value = 121 Then
index = 0
End If
Set Rng = Rng.Offset(1)
Loop
End Sub
Sub Finding_number()
Dim Rng As Range
Set Rng = Range("E2")
Do While Rng.Value <> 121
Set Rng = Rng.Offset(1)
Loop
End Sub
关于vba - "Argument Not Optional"VBA Excel SUB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41062594/
我是一名优秀的程序员,十分优秀!