Hi,
The following code is to select or filter data by clicking a button based on some criteria:
*****************************************
Private Sub CommandButton_Click1()
Application.EnableEvents = True
Dim wsD As Worksheet
Dim wsC As Worksheet
Set wsD = Worksheets("Target Sheet")
Set wsC = Worksheets("Source Data Sheet")
wsC.Range("rangename") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=wsD.Range("A1:F2"), _
CopyToRange:=wsD.Range("A10:AD10")
Application.Calculate
Application.EnableEvents = True
End Sub
***************************************
When I run the Sub in VBE, it works; but when I press the button on the target sheet, there is no reponse at all.
Another question. When I say 'it works', it doesn't mean it works well because the criteria range "A1:F2" has 6 criteria and 5 of them working. Only the first one, which is State, not working. I checked the Data Validation, the State list OK; I checked the range names and they look OK too. There is no single error message and I couldn't find a clue.
It's too bad I cannot attach the workbook but I am not sure if I made myself clear.
Thanks in advance.
jqzhang
The following code is to select or filter data by clicking a button based on some criteria:
*****************************************
Private Sub CommandButton_Click1()
Application.EnableEvents = True
Dim wsD As Worksheet
Dim wsC As Worksheet
Set wsD = Worksheets("Target Sheet")
Set wsC = Worksheets("Source Data Sheet")
wsC.Range("rangename") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=wsD.Range("A1:F2"), _
CopyToRange:=wsD.Range("A10:AD10")
Application.Calculate
Application.EnableEvents = True
End Sub
***************************************
When I run the Sub in VBE, it works; but when I press the button on the target sheet, there is no reponse at all.
Another question. When I say 'it works', it doesn't mean it works well because the criteria range "A1:F2" has 6 criteria and 5 of them working. Only the first one, which is State, not working. I checked the Data Validation, the State list OK; I checked the range names and they look OK too. There is no single error message and I couldn't find a clue.
It's too bad I cannot attach the workbook but I am not sure if I made myself clear.
Thanks in advance.
jqzhang