Greetings,
I've searched high and low and can't find any help for what I'm trying to do. I have been successful in using variables in the AutoFilter Field:= and Criteria1:= keywords...but in my situation I am attempting to push the variables further into the AutoFilter statement.
I have a spreadsheet with multiple sheets that show the client with multiple views of a large table. From the sheet that the user is looking at (analyzing) it's just a summary of the rows of data - I wanted to provide a view of the data based on the table the client is looking at (show them the data behind the summary). I'm not a strong VBA coder but am able to bash code together to make things work (thanks in much to the MrExcel community).
So what I want to do is allow the client to execute the macro via a button and send a string to my AutoFilter macro (successful in passing the parm) and use that STRING AFTER the AutoFilter command. The parm passed would be hard coded for each cell in the table based on "countif" function for each button on the sheet. So if the user click on the button/image I would pass it a string such as "Field:=8, Criteria1:=>90,Operator:=x1And, Criteria2:<100". This string would be assigned to a variable (say AutoStr1) in the macro (I can pass the variable from the sheet to the macro). The string is valid because if I hardcode that into the AutoFilter statement it works. The macro should then take the string and do ".Range("A1:AE1") .AutoFilter AutoStr1. I'm trying this method because AutoStr1 could be a simple 2 criteria statement or much more complex statement with multiple expressions based on the summary table view.
When I invoke the marco from the sheet it fails with "Run-time error '1004': AutoFilter method Range class failed" message. But if I take that exact string and hardcode it into the AutoFilter statement it runs OK...so I'm not sure how/if I can replace all for the statement after the AutoFilter with a string. I've added characters like "&", ".", etc. in a futile attempt at getting the string to be recognized as a valid continuation of the AutoFilter command w/o any luck.
Hopefully I've made clear what I'm attempting to accomlish.
Thanks,
David
I've searched high and low and can't find any help for what I'm trying to do. I have been successful in using variables in the AutoFilter Field:= and Criteria1:= keywords...but in my situation I am attempting to push the variables further into the AutoFilter statement.
I have a spreadsheet with multiple sheets that show the client with multiple views of a large table. From the sheet that the user is looking at (analyzing) it's just a summary of the rows of data - I wanted to provide a view of the data based on the table the client is looking at (show them the data behind the summary). I'm not a strong VBA coder but am able to bash code together to make things work (thanks in much to the MrExcel community).
So what I want to do is allow the client to execute the macro via a button and send a string to my AutoFilter macro (successful in passing the parm) and use that STRING AFTER the AutoFilter command. The parm passed would be hard coded for each cell in the table based on "countif" function for each button on the sheet. So if the user click on the button/image I would pass it a string such as "Field:=8, Criteria1:=>90,Operator:=x1And, Criteria2:<100". This string would be assigned to a variable (say AutoStr1) in the macro (I can pass the variable from the sheet to the macro). The string is valid because if I hardcode that into the AutoFilter statement it works. The macro should then take the string and do ".Range("A1:AE1") .AutoFilter AutoStr1. I'm trying this method because AutoStr1 could be a simple 2 criteria statement or much more complex statement with multiple expressions based on the summary table view.
When I invoke the marco from the sheet it fails with "Run-time error '1004': AutoFilter method Range class failed" message. But if I take that exact string and hardcode it into the AutoFilter statement it runs OK...so I'm not sure how/if I can replace all for the statement after the AutoFilter with a string. I've added characters like "&", ".", etc. in a futile attempt at getting the string to be recognized as a valid continuation of the AutoFilter command w/o any luck.
Hopefully I've made clear what I'm attempting to accomlish.
Thanks,
David