Column Autofit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the code below to autofit the columns on my spreadsheet.

Private Sub Worksheet_Change(ByVal Target As Range)

Me.Application.ActiveWorkbook.RefreshAll
Target.EntireColumn.AutoFit
End Sub

This works fine normally but I have 13 columns on this spreadsheet that
contain Hyperion Retrieve Formula. The values in these columns update when
either D66 or D68 are changed but the column wide is not updating with this.
I end up with the columns either too wide where the value has reduced, or
filled with #### where the number of digits has increased.

Any suggestions how I can resolve this? Help with the code would be great as
I'm just finding my feet with VBA.
 
Karen,

Try:


Private Sub Worksheet_Change(ByVal Target As Range)
Me.Application.ActiveWorkbook.RefreshAll
Target.EntireColumn.AutoFit

On Error Resume Next
Target.Dependents.EntireColumn.AutoFit
End Sub
 
That works brilliantly!

Thanks for your help

Vergel Adriano said:
Karen,

Try:


Private Sub Worksheet_Change(ByVal Target As Range)
Me.Application.ActiveWorkbook.RefreshAll
Target.EntireColumn.AutoFit

On Error Resume Next
Target.Dependents.EntireColumn.AutoFit
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top