如何修复 VBA 缺少过程错误?

问题描述 投票:0回答:1

我正在尝试创建一个 Excel 工作簿,可以在其中填充数字 1-99 的数组。 我尝试创建的过程是通过单击链接到 VBA 宏的按钮来选择数字,该宏将引用单元格中的数字复制到我单击的下一个单元格。 这是我的 VBA 代码:

Public Sub Number3(ByVal Target As Range)
    If Selection.Count = 1 Then
        ' Specify your actual range and adjust the destination cell
        If Not Intersect(Target, Range("G15")) Is Nothing Then
            Dim clickedValue As Variant
            clickedValue = Target.Value
            Target.Offset(1, 0).Value = clickedValue
        End If
    End If
End Sub

我希望 a) 这个可以工作,b) 如何扩展它,以便单击一个按钮后最多可以处理 10 次点击

当我单击按钮时,出现此错误

enter image description here

我很乐意上传我的工作簿,但我不认为这是一个选项。

我尝试将例行公事设为私人

我尝试添加 Cancel = True,建议在线

excel vba compilation
1个回答
0
投票

试试这个:

Public Sub Number3()
    If Selection.Count = 1 Then
        ' Specify your actual range and adjust the destination cell
        If Not Intersect(Selection, Range("G15")) Is Nothing Then
            Dim clickedValue As Variant
            clickedValue = Selection.Value
            Selection.Offset(1, 0).Value = clickedValue
        End If
    End If
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.