1

When my code executes the following line, I'm getting the "Select method of Range class failed" error message

 Range(Workbooks(FileName).Worksheets(ShtName).Cells(1, 1), Workbooks(FileName).Worksheets(ShtName).Cells(LastRow, 30)).Select

I'm using variables for the workbook, sheet and last data row. Why am I getting this error message?

My machine is using Windows 10 and Office 2016. Thanks for the help....

Shaves
  • 884
  • 5
  • 16
  • 46
  • 1
    You shouldn't `Select` though...https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba – BigBen Mar 09 '20 at 16:43
  • You also shouldn't use `String` variables here, rather `Workbook` and `Worksheet` variables. – BigBen Mar 09 '20 at 16:46
  • 2
    `Workbooks(FileName).Worksheets(ShtName).Cells(1, 1).Resize(LastRow, 30).Select` but you probably don't need to select. Also you can't select a Range if the parent sheet isn't active. – Tim Williams Mar 09 '20 at 16:47

0 Answers0