VBA Debug showing error in the highlighted line. I need a selection i.e. range to be dynamic

44 Views Asked by At

Error is "script out of range". I want range selection to be relative i.e dynamic.

Sub input_file()
    Dim FileToOpen As Variant
    Dim Openbook As Workbook
    Application.ScreenUpdating = False
    FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files(*.xls*),*xls*")
    If FileToOpen <> False Then
        Set Openbook = Application.Workbooks.Open(FileToOpen)
        Openbook.Sheets(2).Range("A2:AZ2").Copy
        ThisWorkbook.Worksheets("SelectFile").Range("A3").Active.PasteSpecial xlPasteValues
        OpenWorkbook.Close False
        
    End If
    Application.ScreenUpdating = True
End Sub
0

There are 0 best solutions below