| 
            Sub sample()
 
 '================= 先月の日付を抽出するマクロ  ===========
 
 
 
 Dim DateOne As Date '先月の1日
 Dim DateB As Date   '先月の最終日
 
 
 
 
 
 '#########################################################
 '先月の1日を取得 ========================================
 '#########################################################
 
 
 '先月 ====================================================
 If Month(Date) <> 1 Then '今月が1月でないならば。
 
 YearOne = Year(Date)
 MonthOne = Month(Date) - 1
 DayOne = 1
 
 '先月の1日を文字列にする
 DateStringA = YearOne & "/" & MonthOne & "/" & DayOne
 
 '文字列の日付に変換
 DateOne = DateValue(DateStringA)
 
 
 Else  '今月が1月だったら
 
 YearOne = Year(Date) - 1
 MonthOne = 12
 DayOne = 1
 
 '先月の1日を文字列にする
 DateStringA = YearOne & "/" & MonthOne & "/" & DayOne
 
 '文字列を日付に変換
 DateOne = DateValue(DateStringA)
 
 
 End If
 
 
 
 
 
 
 '##############################################################
 '先月の最終日を取得 // 「今月の1日 - 1」が先月の最終日。=========
 '##############################################################
 
 YearB = Year(Date)
 MonthB = Month(Date)
 DayB = 1
 
 '今月の1日を文字列にする
 DateStringB = YearB & "/" & MonthB & "/" & DayB
 
 
 '文字列を日付に変換。 // 「今月の1日 - 1」が先月の最終日。
 DateB = DateValue(DateStringB) - 1
 
 
 
 
 '#########################################################
 '抽出条件をシートに転記==================================
 '########################################################
 
 '抽出の条件式
 '先月の1日
 Cells(4, "C").Value = ">=" & DateOne
 
 
 '先月の最終日
 Cells(4, "D").Value = "<=" & DateB
 
 
 Range("B9:D70").AdvancedFilter Action:=xlFilterInPlace, _
 CriteriaRange:=Range("C3:D4"), Unique:=False
 
 
 
 End Sub
 
 
 |