How to Preserve Column Width Formatting After Data Refresh in Excel 2013

I'm stumped!

Using Excel 2013, I have the following Macro:

Sub Macro7()
'
    Sheets("Full DataSet").Select
    Cells.Select
    ActiveWorkbook.RefreshAll
    Range("A5").Select
    Sheets("Parish Council").Select
    Cells.Select
    Selection.Columns.AutoFit
    Range("A5").Select
End Sub

Open in new window


If I do the commands manually, that is:

Select the Worksheet
Refresh All the Data
Press <Alt> OCA (to do AutoWidth)

The commands work.  BUT in a macro, zippo, nada, zilch, nothing.  Refresh works but the columnwidth will not go back.

Any thoughts would be greatly appreciated.

Louis
LCSLouisJJamesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wilder1626Commented:
Hi
for the autofit multiple columns, you can use this macro:
Worksheets("Parish Council").Columns("A:I").AutoFit

Open in new window


If you only have 1 column, you can do like this:
Worksheets("Parish Council").Columns("A:A").AutoFit

Open in new window


Just need to put the good sheet name and the good columns.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wilder1626Commented:
At the end, your full macro can look like:
ActiveWorkbook.RefreshAll
Worksheets("Parish Council").Columns("A:AA").AutoFit

Open in new window


This is if the columns you want to autofit are A to AA. You can adjust.

Also the Refreshall will be done.

Can you give it a try?
0
LCSLouisJJamesAuthor Commented:
Perfect.  Excellent answer and it worked.  Thanks.
0
Wilder1626Commented:
I'm glad i was able to help.

Have you also tried my last answer?

You can simplify the full macro like this:

ActiveWorkbook.RefreshAll
Worksheets("Parish Council").Columns("A:AA").AutoFit

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.