pasting of variable cell value into macro

E

ELDANS

I have written a macro that runs an autofilter which grabs cell info from a
different worksheet within that workbook (an entered date). It then uses that
date to autofilter. It works fine the first time, but aparently plugs that
info permanently into the macro and will not work on subsequent runs. I need
a macro that will grab variable info from a certain cell each time and run
with that new cell value each time. Any ideas?. (& yes, I am a newbee)
sorry..
 
G

Gary''s Student

Your problem is refreshing the autofilter. It is best to clear the old
filter before applying the new filter. Here is an example:

Sub puralator()
Dim s As String
s = Sheets("Sheet2").Range("A1").Value
Sheets("Sheet1").Activate
Range("A1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1
Selection.AutoFilter Field:=1, Criteria1:=s
End Sub
 
G

Gord Dibben

Maybe use ActiveCell.value instead of Range("A1").value as filter criterion
but hard to say without seeing your code.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top