Excel VBA中的对象必需错误 [英] Object Required Error in excel VBA
本文介绍了Excel VBA中的对象必需错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim g1val, g2val As Integer
Set g1val = 0
Set g2val = 0
For i = 3 To 18
If g1val > Cells(33, i).Value Then
g1val = g1val
Else
g1val = Cells(33, i).Value
End If
Next i
For j = 32 To 57
If g2val > Cells(31, j).Value Then
g2val = g2val
Else
g2val = Cells(31, j).Value
End If
Next j
在第二行中,我收到一条错误消息,指出需要对象.我试图将g1val和g2val设置为"Double",并尝试首先给它们的值赋予1.但是这些都没有解决.你能帮忙吗?? ....
Here on second line i am getting an error saying object required.I have tried to make g1val and g2val as "Double" and tried to give 1 for their values at first.But those didn't work out. Can u help??....
推荐答案
为了设置整数变量的值,我们只需为其分配值.
例如g1val = 0
,其中set关键字用于为对象分配值.
In order to set the value of integer variable we simply assign the value to it.
eg g1val = 0
where as set keyword is used to assign value to object.
Sub test()
Dim g1val, g2val As Integer
g1val = 0
g2val = 0
For i = 3 To 18
If g1val > Cells(33, i).Value Then
g1val = g1val
Else
g1val = Cells(33, i).Value
End If
Next i
For j = 32 To 57
If g2val > Cells(31, j).Value Then
g2val = g2val
Else
g2val = Cells(31, j).Value
End If
Next j
End Sub
这篇关于Excel VBA中的对象必需错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文