VBA Help Needed: How to Unprotect sheet, Update Stocks on Excel sheet, Reprotect sheet

10 pts.
Tags:
Microsoft Excel
VBA
I was trying to update some stocks and commodities links on a protected sheet by creating a button to update but before the update occurs the sheet becomes protected. If I disable the re-protection of the sheet it will updated the stocks and commodity prices but the columns width doesn’t adjust automatically based on the code below. I was also wondering why the codes do not run in the order they are written.
Private Sub CommandButton1_Click()

Sheets("DBN NetBacks").Unprotect Password:="abcdef"
ActiveWorkbook.RefreshAll
If Sheets("DBN NetBacks").Range("H7:I24:J50").Columns.AutoFit        Then
Sheets("DBN NetBacks").Columns("H:J").AutoFit

End If

If Sheets("DBN NetBacks").ProtectContents = False               Then

Sheets("DBN NetBacks").Protect Password:="abcdef"

End If

End Sub


Software/Hardware used:
Excel 2010 & Window 7
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: