简体   繁体   中英

Excel vba - column selection error

I need to autofit first two columns from Sheetx , but I want to be able to start MACRO from any other sheet so I'm using With-method. How to avoid using Select in this case?

Set ws = ThisWorkbook.Sheets("Sheetx")

With ws

    .Columns("A:B").Select

    Selection.EntireColumn.AutoFit

End with
Set ws = ThisWorkbook.Sheets("Sheetx")

With ws
    .Columns("A:B").AutoFit
End with

This might help you aswell.

Like this:

Set ws = ThisWorkbook.Sheets("Sheetx")

With ws
    .Columns("A:B").AutoFit
End with

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM