运行时错误 13 VBA

运行时错误 13 VBA

我是 vba 新手,正在尝试运行代码。我只是收到运行时错误 13 - 类型不匹配

代码如下:

Sub Range_Copy_Examples()
Worksheets("Luni").Range("A1:A800").Value = Worksheets("Rout").Range("A1:A800").Value
Worksheets("Luni").Range("B1:B800").Value = Worksheets("Rout").Range("B1:B800").Value
Worksheets("Luni").Range("C1:C800").Value = Worksheets("Rout").Range("C1:C800").Value
Worksheets("Luni").Range("D1:D800").Value = Worksheets("Rout").Range("D1:D800").Value
Worksheets("Luni").Range("E1:E800").Value = Worksheets("Rout").Range("E1:E800").Value
Worksheets("Luni").Range("F1:F800").Value = Worksheets("Rout").Range("F1:F800").Value
Worksheets("Luni").Range("G1:G800").Value = Worksheets("Rout").Range("G1:G800").Value
Worksheets("Luni").Range("H1:H800").Value = Worksheets("Rout").Range("H1:H800").Value
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("A1:A800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("A1:A800").PasteSpecial Paste:=xlPasteFormats
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("B1:B800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("B1:B800").PasteSpecial Paste:=xlPasteFormats
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("C1:C800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("C1:C800").PasteSpecial Paste:=xlPasteFormats
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("D1:D800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("D1:D800").PasteSpecial Paste:=xlPasteFormats
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("E1:E800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("E1:E800").PasteSpecial Paste:=xlPasteFormats
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("F1:F800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("F1:F800").PasteSpecial Paste:=xlPasteFormats
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("G1:G800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("G1:G800").PasteSpecial Paste:=xlPasteFormats
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Rout").Range("H1:H800").Copy
Workbooks("Plan livrari 2018 Landscape - final.xlsm").Worksheets("Luni").Range("H1:H800").PasteSpecial Paste:=xlPasteFormats
End sub

   If Target = Range("F4") Then
        If ActiveSheet.Range("F4").Value <> "" Then
            ActiveSheet.Shapes("CheckBox2").Visible = True
        Else
            ActiveSheet.Shapes("CheckBox2").Visible = False
        End If
    End If

    If Target = Range("F5") Then
        If ActiveSheet.Range("F5").Value <> "" Then
            ActiveSheet.Shapes("CheckBox2").Visible = True
        Else
            ActiveSheet.Shapes("CheckBox2").Visible = False
        End If
    End If

      If Target = Range("F6") Then
        If ActiveSheet.Range("F6").Value <> "" Then
            ActiveSheet.Shapes("CheckBox3").Visible = True
        Else
            ActiveSheet.Shapes("CheckBox3").Visible = False
        End If
End sub

我收到运行时错误 13 - 类型不匹配,并且调试突出显示如下:

If Target = Range("F4") Then

答案1

Target未在您发布的代码中任何地方声明(它可能是全局声明的变量),并且您可能未Option Explicit启用。启用Option Explicit通常是一个好主意,它会在运行前为未声明的变量抛出错误。

错误是因为Range()返回一个 Range 对象,并且Target可能不是ObjectnorRange数据类型。

Target您可能从在声明中将其声明为参数的示例中粘贴了此内容Sub

如果这些都没有任何意义,你需要阅读一些资料。

相关内容