A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Do you get an error message when you click the refresh button? If so, what does it say?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a template with tab sheet1 and sheet2. In sheet1, there is a command2 button to filter data and fillout column A to F in sheet2. and there is refresh button in sheet2 to refresh query table in column H to pulling data from sheet1.
I wonder if there is a code to protected the sheet2 column A to F and H to prevent user accident add/edit or delete data. But it should allow command2 button and refresh button to clear and filling out new information.
Here is the code for command2 button.
Private Sub CommandButton2_Click()
Dim UserRange As Range
Sheets("SHEET2").Range("A:A,C:C,E:E,H3:H100").Clear
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("SHEET1")
On Error Resume Next
Set UserRange = Application.Range("E23:E500")
On Error GoTo 0
If UserRange Is Nothing Then
Exit Sub
End If
UserRange.AdvancedFilter xlFilterCopy, CopyToRange:=Sheets("SHEET2").Range("A1"), Unique:=True
'------------------
Set sh = ThisWorkbook.Sheets("SHEET1")
On Error Resume Next
Set UserRange = Application.Range("H23:H500")
On Error GoTo 0
If UserRange Is Nothing Then
Exit Sub
End If
UserRange.AdvancedFilter xlFilterCopy, CopyToRange:=Sheets("SHEET2").Range("C1"), Unique:=True
'------------------
Set sh = ThisWorkbook.Sheets("SHEET1")
On Error Resume Next
Set UserRange = Application.Range("K23:K500")
On Error GoTo 0
If UserRange Is Nothing Then
Exit Sub
End If
UserRange.AdvancedFilter xlFilterCopy, CopyToRange:=Sheets("SHEET2").Range("E1"), Unique:=True
End Sub
Here is the refresh VBA Code
Sub RefreshAll()
ActiveWorkbook.RefreshAll
End Sub
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
Do you get an error message when you click the refresh button? If so, what does it say?
There are three tabs in the workbook. but they are not protected. Only the one in sheet2 is protected by the code you provided above.
Do you have other protected sheets in the workbook? If so, you should unprotect and protect them too.
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more