Hi All,
First time poster here and very new to VBA script.. learning as I go as of a couple days ago.
Before I get into the problem, here is some context. (Hopefully it makes sense)
I have been working on an excel document that pulls data from an online source.
There are 4 sheets on this document. Sheets1 and 2 and like a dashboard that presents the findings from the data.
Sheets 3 and 4 show the summarised background data for people who would like to drill into the details.
The background data sheets (3 & 4) are the product of me using power queries to filter out and amend the info from online data source.
Now the task:
I have created refresh buttons on Sheets 1 & 2 that are meant to refresh the query data.
In amongst that, I would also like Sheets 3 & 4 protected so the data cannot be altered before it gets displayed onto sheets 1 & 2.
(The online data source also requires a login so whoever doesn't have an account cannot refresh the data or edit the queries. This is by done design)
The Script:
The issue:
Now it runs well. Does everything that is required, but when I click on one of the refresh buttons I created, lets say on Sheet 1, the macro makes Sheet 3 active, every time.
I want it to refresh without activating another sheet.
Some more info:
I have disabled background refresh on the queries and the data refresh also takes a bit of time. I tried adding in a delay from Unprotect to RefreshAll and that doesn't fix the problem. Also tried to do it on a clean version of the file, so no other accidental macros in the background...
Thanks in advance for your help and really excited to be learning a new skill.
First time poster here and very new to VBA script.. learning as I go as of a couple days ago.
Before I get into the problem, here is some context. (Hopefully it makes sense)
I have been working on an excel document that pulls data from an online source.
There are 4 sheets on this document. Sheets1 and 2 and like a dashboard that presents the findings from the data.
Sheets 3 and 4 show the summarised background data for people who would like to drill into the details.
The background data sheets (3 & 4) are the product of me using power queries to filter out and amend the info from online data source.
Now the task:
I have created refresh buttons on Sheets 1 & 2 that are meant to refresh the query data.
In amongst that, I would also like Sheets 3 & 4 protected so the data cannot be altered before it gets displayed onto sheets 1 & 2.
(The online data source also requires a login so whoever doesn't have an account cannot refresh the data or edit the queries. This is by done design)
The Script:
VBA Code:
Sub DataRefresh()
Sheet3.Unprotect ("123")
Sheet4.Unprotect ("123")
ActiveWorkbook.RefreshAll
Sheet1.Range("A11").Value = Now()
Sheet1.Range("A13").Value = Application.UserName
Sheet1.Columns("A").AutoFit
Sheet2.Range("A11").Value = Now()
Sheet2.Range("A13").Value = Application.UserName
Sheet2.Columns("A").AutoFit
Sheet3.Protect ("123")
Sheet4.Protect ("123")
End Sub
The issue:
Now it runs well. Does everything that is required, but when I click on one of the refresh buttons I created, lets say on Sheet 1, the macro makes Sheet 3 active, every time.
I want it to refresh without activating another sheet.
Some more info:
I have disabled background refresh on the queries and the data refresh also takes a bit of time. I tried adding in a delay from Unprotect to RefreshAll and that doesn't fix the problem. Also tried to do it on a clean version of the file, so no other accidental macros in the background...
Thanks in advance for your help and really excited to be learning a new skill.