0

I have a debug button on a userform. The debug button needs to do 2 things:

Auto Size row 17 Auto size Column X.

I have tryied this: ThisWorkbook.Worksheets("Sheet2").Columns("X").EntireColumn.AutoFit ThisWorkbook.Worksheets("Sheet2").Columns("17").EntireRow.AutoFit

The sheet is not protected and yet I get Subscript out of range (Error 9).

BigBen
  • 46,229
  • 7
  • 24
  • 40
DVT
  • 3
  • 2
  • Your workbook has no sheet named Sheet2. Also, `17`, not `"17"`. Also, did you mean `Rows` instead of `Columns` in the second line? – BigBen Mar 10 '23 at 16:58

1 Answers1

0
to AutoFit EntireRow
ThisWorkbook.Worksheets("Sheet2").Columns(17).EntireRow.AutoFit
to AutoFit EntireColumn
ThisWorkbook.Worksheets("Sheet2").Columns(17).EntireColumn.AutoFit
abdomohamed
  • 134
  • 1
  • 5