I was looking into how to create a shortcut with the help of VBA. The macro would basically allow me to filter the range based on cell's value. I found this macro on the internet
Public Sub FilterOnCellValue()
Dim nField As Long
With ActiveCell
nField = .Column - .CurrentRegion.Cells(1).Column + 1
.CurrentRegion.AutoFilter Field:=nField, Criteria1:=.Value
End With
End Sub
The code works fine, but I have a hard time trying to understant how the dude create. So what I know so far is the guys is creating a variable. but for some reason the variable is not in a string format but in "long" and the code works perfectly when I filter based on text in a cell. I thought that long can only be used for numbers, correct me if I am wrong (which i think I am:)). Secondly. whats up with .column - .currentregion. cells.....+1
? I real have no idea what he did there.
Would really appreciate some help here. the forum has been very useful to me so far.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…