Macro chaning

P

pcor

I currently use the following macro:
Selection.AutoFilter Field:=1, Criteria1:="<>"

How can I change thus macro so that the "1"in field would be changed to the
cell that is selected.
(IE how do I capture the cell where the cursor is located when I run this
macro
In visual basic the code would be something like:
d$=celladdress
Field=d$
Thanks
 
M

Mark

pcor said:
I currently use the following macro:
Selection.AutoFilter Field:=1, Criteria1:="<>"

How can I change thus macro so that the "1"in field would be changed to the
cell that is selected.
(IE how do I capture the cell where the cursor is located when I run this
macro
In visual basic the code would be something like:
d$=celladdress
Field=d$
Thanks

Try:
Selection.AutoFilter Field:=Application.ActiveCell,Criteria1:="<>"
 
D

Dave Peterson

How about something like:

Option Explicit
Sub testme()

Dim myCol As Long

With ActiveSheet
If Intersect(.AutoFilter.Range, ActiveCell) Is Nothing Then
Beep
Exit Sub
End If
myCol = ActiveCell.Column - .AutoFilter.Range.Column + 1
.AutoFilter.Range.AutoFilter Field:=myCol, Criteria1:="<>"
End With

End Sub
 
G

Gord Dibben

pcor

Selection.AutoFilter Field:=ActiveCell.Column, Criteria1:="<>"


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