Hello everybody,
I have searched online a solution to this issue and it is first time when I find one. Thanks to watersev I think many users will be able to go beyond an excel limitation: respectively, to use the Autofilter property "begins with" not just for text format data but for numbers too. Because I have considered this kind of filtering could be very useful in many cases, I have written a function so that to make entire solution more intelligible for everyone:
Option Base 1
Sub filterCaling()
Dim myFilter As Variant, U As Range
Set U = Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
'myFilter array will contain all numbers that "begins with" 1
myFilter = FilterByDigit(U, 1)
'If we want, we can transpose the results somewhere in an empty column
Range("B2:B" & 2 + UBound(myFilter) - 1).Value = WorksheetFunction.Transpose(myFilter)
Set U = Nothing
End Sub
Private Function FilterByDigit(myRange As Range, digit As String) 'by watersev
Dim arr1 As Variant, arr2 As Variant
Dim str1 As String, str2 As String
arr1 = WorksheetFunction.Transpose(myRange) 'Create one-dimensional array
str1 = "#" & Join(arr1, "|#") 'Join this array, delimited by "|#"
str2 = Replace(str1, "#" & digit, digit) 'Replace "# & number" to number only
arr2 = Split(str2, "|") 'Create a new array by splitting
arr1 = Filter(arr2, "#", False) 'Filter last array with elements without #
'by mikerikson's idea: Restructurate an array so that to have base 1 ...
FilterByDigit = WorksheetFunction.Index(arr1, 1, 0)
End Function
In the code lines above I have modified str1 = "|#" with str1 = "#" because in the splitting function I had getting
an inconvenient position of the first value...
Five globes for this solving, watersev. Many thanks.
Daniel
Bookmarks