Excel / VBA: auto-adjust column width after pasting data

后端 未结 3 940
孤独总比滥情好
孤独总比滥情好 2021-02-14 10:35

I have a blank Excel table saved as a template into which I copy data from the clipboard (originating from a website).

Is there a way using VBA to auto-adjust the width

相关标签:
3条回答
  • 2021-02-14 11:13

    You can do it with a worksheet change event, but if your worksheet is changed in any way after the paste, it runs again. Not an issue unless you're trying to hide columns to focus on a subset of data because they will autofit themselves constantly.

    I recommend using a button to paste the data and including the column width setting as part of the paste command.

    0 讨论(0)
  • 2021-02-14 11:23

    You can perform the following:

    Columns("A").Autofit
    
    0 讨论(0)
  • 2021-02-14 11:35

    You can do it with AutoFit:

     Columns("A:B").EntireColumn.AutoFit
    
    0 讨论(0)
提交回复
热议问题