검색/필터 userform에서 작업하고 날짜 필터링시 문제가 있습니다.Excel VBA 날짜순으로 정렬
문자열을 포함하고 있는지 판단하기 위해 날짜를 비교하면 잘 작동하는 것처럼 보입니다. 비교할 때 문자열로 캐스팅한다고 생각합니다. 날짜 열을 기준으로 필터링 할 때가되면 주어진 문자열이 포함 된 행을 인식하지 못하고 시트에서 모든 것을 제거합니다.
예 :
필터 문자열 :가 포함되어 이후는, 라인 (1)과 (4)는 표시 할
Date entries: 6/15/1956
4/3/1971
10/13/1960
2/16/1983
6/(기본적으로 와일드 카드 (*) 각 측에 배치된다) " 6/"
나는 날짜 객체가 실제로 일종의 배열이라는 것을 알고 있습니다. 내가 이슈가되는 이유는 무엇일까요? 정상적인 자동 필터로 내가 원하는 것을 할 수 없습니까? 날짜 열을 기준으로 정렬 할 때 특별한 경우를 만들어야합니까? 다른 데이터 유형 (예 : 돈, 시간 등)에도 적용됩니까?
감사
이 내가 뭘 찾았는지 참조필터 코드 (변수가 선언되지 않은 경우, 그들은 전역 또는 정크 변수 중 하나입니다)
Private Sub Filter_CommandButton_Click()
'Filters by a text input and a column to filter
Dim isInCol As Boolean
Dim sortKey As String
Dim sortOrder As XlSortOrder
Dim currentData As Range
Dim sortField As Integer ' This is the offset, determined by list index
If filterColumn Is Nothing Then
gojira = MsgBox("You need to enter a column to filter", vbOKOnly)
Exit Sub
End If
' setting active sheet complete data
Set currentData = ActiveSheet.UsedRange
' make sort key a wildcard
If include = True Then
sortKey = "*" & filterText & "*"
Else ' for excluding the entered text
sortKey = "<>" & "*" & filterText & "*"
End If
' find list index for sorting
sortField = Me.ColumnFilter_ComboBox.ListIndex + 1
' populate sort order with value of Ascend/Descend options.
If descend Then
sortOrder = xlDescending
Else
sortOrder = xlAscending
End If
' Search column to see if text exists
isInCol = False
For Each foo In filterColumn
If caseSense Then
If InStr(foo.Value, filterText) Then ' > 0 Then
isInCol = True
Exit For
End If
ElseIf Not caseSense Then
If InStr(LCase(foo.Value), LCase(filterText)) Then
isInCol = True
Exit For
End If
End If
Next foo
If isInCol Then ' filter the table by the selected col; Use Range Sort
With ActiveSheet
currentData.AutoFilter Field:=sortField, Criteria1:=sortKey, VisibleDropDown:=False
currentData.Sort key1:=filterColumn, Order1:=sortOrder, Header:=xlYes
End With
End If
blah = bleh
End Sub
나는 귀하의 날짜가 실제로 귀하의 테이블에 날짜 형식으로되어 있다면 문제라고 생각합니다. 즉 숫자로 저장된다는 의미입니다. 따라서'6/15/1956'은'20621'으로 저장됩니다. 그리고 그 경우에, 당신은 날짜에'6 /'을 절대로 발견 할 수 없을 것입니다. – guitarthrower
예, 날짜 형식입니다. 그래서 나는 SOL 인 것처럼 들린다. 다른 옵션이 없다면 시도해 주셔서 감사합니다. – JSM
도우미 열을 만들 수 있다면 여전히 사용할 수 있습니다. 헬퍼 컬럼은'= "_"& B2' (B2가 날짜 인 경우)와 같이 쉽게 될 수 있고 그것을 복사 할 수 있습니다. 그런 다음 도우미 열에서 설명하는 동작을 수행 할 수 있습니다. – guitarthrower