0

我有以下代码:

Dim FinalAddr As Range
Dim Final As String

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next


Select Case UCase(Target.Value)


   Case "NEW-BOX"
        Selection.Offset(-1, 2).Select
        FinalAddr = Range(Selection.Address)
        MsgBox FinalAddr ' Debug, nothing comes up however
        Selection.ClearContents
        Selection.Offset(1, -2).Select

   Case "END-BOX"
        Final = FinalAddr.Value
        Application.Speech.Speak (Final)

    End Select
End Sub

但是,当我扫描新盒子时没有任何反应,所有语法都正确吗?我没有错误,任何输入将不胜感激。

4

2 回答 2

2

这就是你所追求的吗?

   Case "NEW-BOX"
        Selection.Offset(-1, 2).Select
        MsgBox Selection.Address ' Debug, nothing comes up however
        Selection.ClearContents
        Selection.Offset(1, -2).Select

编辑:如果您想将 FinalAddr 设置为选择,然后测试它是否有效:

   Case "NEW-BOX"
        Selection.Offset(-1, 2).Select
        Set FinalAddr = Selection
        MsgBox FinalAddr ' Debug, nothing comes up however
        Selection.ClearContents
        Selection.Offset(1, -2).Select
于 2013-02-26T10:36:39.927 回答
0

如果你想要你应该使用的单元格中的值 Finaladdr = Selection.Value,但是如果你想要你应该使用的选择的地址= Selection.AddressLocal()

但是,如果您想引用您需要使用的范围Set,然后.AddressLocal()在引用单元格地址时。

于 2013-02-26T10:37:38.310 回答