VBA error 1004 - select method of range class failed

前端 未结 4 1950
臣服心动
臣服心动 2020-12-05 18:31

First time poster, so if there is any formatting, or guidelines I failed to adhere to, please let me know so that I can fix it.

So I am basically asking the user fo

4条回答
  •  伪装坚强ぢ
    2020-12-05 19:14

    You have to select the sheet before you can select the range.

    I've simplified the example to isolate the problem. Try this:

    Option Explicit
    
    
    Sub RangeError()
    
        Dim sourceBook As Workbook
        Dim sourceSheet As Worksheet
        Dim sourceSheetSum As Worksheet
    
        Set sourceBook = ActiveWorkbook
        Set sourceSheet = sourceBook.Sheets("Sheet1")
        Set sourceSheetSum = sourceBook.Sheets("Sheet2")
    
        sourceSheetSum.Select
    
        sourceSheetSum.Range("C3").Select           'THIS IS THE PROBLEM LINE
    
    End Sub
    

    Replace Sheet1 and Sheet2 with your sheet names.

    IMPORTANT NOTE: Using Variants is dangerous and can lead to difficult-to-kill bugs. Use them only if you have a very specific reason for doing so.

提交回复
热议问题