.Range.Select

时间:2018-01-19 08:38:00

标签: excel vba excel-vba

如何限定以下工作表/范围以使代码不返回

  

1004 Range类失败的选择方法

在最后一行?

Sub MarketsBudgetOverviewPDF()

Dim wb1 as Workbook
Dim MarketsBudgetPDFTemplate As Worksheet
Dim TemplateHeader As Range

Set wb1 = ThisWorkbook
Set MarketsBudgetPDFTemplate = wb1.Worksheets("Markets budget overview PDF")
Set TemplateHeader = MarketsBudgetPDFTemplate.Range("A1")

TemplateHeader.Select

End Sub

2 个答案:

答案 0 :(得分:2)

以下内容如何:

Sub MarketsBudgetOverviewPDF()
Dim wb1 As Workbook
Dim MarketsBudgetPDFTemplate As Worksheet
Dim TemplateHeader As Range
Set wb1 = ThisWorkbook
Set MarketsBudgetPDFTemplate = wb1.Worksheets("Markets budget overview PDF")
Set TemplateHeader = MarketsBudgetPDFTemplate.Range("A1")

    MarketsBudgetPDFTemplate.Select
    'select the sheet above before selecting the Range below
    TemplateHeader.Select
End Sub

答案 1 :(得分:1)

您可以使用Goto,而不是预先选择工作表,如果需要,可以激活工作表,然后选择范围/单元格。

Application.Goto TemplateHeader