View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Colin Hayes Colin Hayes is offline
external usenet poster
 
Posts: 465
Default VBA to Filter on variable column


Hi Claus

Excellent - thank you. It works first time perfectly. I'm grateful.

BTW - would be an easy thing for the filter to show all rows containing
the input value rather than a strict literal match?

So , for example the input filter of "LP" would return rows with

LP
2LP
3LP

rather then just LP.

Thanks Claus.


In article , Claus Busch
writes
Hi Colin,

Am Mon, 26 May 2014 21:16:52 +0100 schrieb Colin Hayes:

The column would then show those rows corresponding to the user input in
the selected column.


here is a suggestion with only one inputbox to enter column letter and
filter value comma separated:

Sub myFilter()
Dim myStr As String
Dim myArr As Variant

With ActiveSheet
.AutoFilterMode = False
myStr = Application.InputBox("Enter the column letter" _
& "and the filter value comma separated", _
"Column and Value Choice", Type:=2)
If myStr = "" Or myStr = "False" Then Exit Sub

myArr = Split(myStr, ",")
.UsedRange.AutoFilter field:=Columns(myArr(0)).Column, _
Criteria1:=Trim(myArr(1))
End With

End Sub


Regards
Claus B.