我想搜索属于一个月的所有日期。用户将选择月份。我无法搜索所有日期,只能得到输入的最后一个日期。我正在使用查找功能,无法提供具体条件。
mois = InputBox("Choisissez le mois (Entrer la valeur Numérique)!!! (1 pour Janvier, 2 pour Fév .... )", "Titre")
If mois > 0 & mois < 12 Then
' Search for matching date
Set cellsearch = Range("G1:G" & NbrLinesDate).Find(What:=mois_chercher)
If cellsearch Is Nothing Then
If mois < 0 Then
ElseIf mois > 12 Then
End If
Else
ligne = cellsearch.Row
Date_to_search = Range("G" & ligne).Value
End If
End If
MsgBox Date_to_search '' Checkpoint_1
JourTest = Day(Date_to_search)
JourTest = Trim(JourTest)
MsgBox JourTest '' Checkpoint_2
Mois是变量,用于存储用户提供的月份值。在这段代码中,我没有使用此变量mois搜索属于该月的日期。我无法实现这一目标。
Date_de_Survenance
30/01/2013
31/01/2013
31/01/2013
04/02/2013
05/02/2013
07/02/2013
11/02/2013
13/02/2013
13/02/2013
13/02/2013
15/02/2013
20/02/2013
请参阅此示例。我不是使用Inputbox
来接受输入,而是使用硬编码值来进行演示。
可以说您的Excel数据如下所示。
只需将此代码粘贴到模块中并运行即可。
代码
'
' Excel Constants for Months for Autofilter
'
' xlFilterAllDatesInPeriodJanuary = 21
' xlFilterAllDatesInPeriodFebruray = 22
' xlFilterAllDatesInPeriodMarch = 23
' xlFilterAllDatesInPeriodApril = 24
' xlFilterAllDatesInPeriodMay = 25
' xlFilterAllDatesInPeriodJune = 26
' xlFilterAllDatesInPeriodJuly = 27
' xlFilterAllDatesInPeriodAugust = 28
' xlFilterAllDatesInPeriodSeptember = 29
' xlFilterAllDatesInPeriodOctober = 30
' xlFilterAllDatesInPeriodNovember = 31
' xlFilterAllDatesInPeriodDecember = 32
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long, lMnth As Long, constmonth As Long
'~~> Feb
lMnth = 2
constmonth = lMnth + 20 '~~> (See the commented section for constants)
'~~> Change this to the relevant sheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
'~~> Remove any filters
.AutoFilterMode = False
With .Range("A1:A" & lRow)
.AutoFilter Field:=1, Criteria1:= _
constmonth, Operator:=xlFilterDynamic
End With
End With
End Sub
输出
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句