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

user2571510 picture user2571510 · Jun 5, 2014 · Viewed 71.4k times · Source

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 of each column to its content after the data (text) has been pasted in ?

Edit: The data I paste will always be inserted starting from A1 and will always fill the same number of columns.

Answer

InformatikBabo picture InformatikBabo · Jun 5, 2014

You can do it with AutoFit:

 Columns("A:B").EntireColumn.AutoFit