gpt4 book ai didi

vba - Excel VBA 中需要对象错误

转载 作者:行者123 更新时间:2023-12-01 18:11:08 24 4
gpt4 key购买 nike

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。但这些都没有成功。你能帮忙吗?......

最佳答案

为了设置整型变量的值,我们只需将值赋给它即可。例如 g1val = 0 其中 as set 关键字用于为对象赋值。

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

关于vba - Excel VBA 中需要对象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19048601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com