1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

20締で年月度と年度を求める関数をVBAで作る

Posted at

環境

Excel 2019で検証

###経緯
20締で月度と年度が必要になりました。
標準関数でも作成できそうですが、関数の入れ子が気持ち悪いので作成してみた。

年月度を求めるコード

引数:日付
戻値:計上年月度

Function get_getsudo(mydate As Date) As String

    Dim myyear
    Dim mymonth
    Dim myday
    
    myyear = Year(mydate)
    mymonth = Month(mydate)
    myday = Day(mydate)

    If myday >= 21 Then
        myday = 21
        mymonth = mymonth + 1
        
        If mymonth = 13 Then
        mymonth = 1
            myyear = myyear + 1
        End If
      Else
    End If
    
    get_getsudo = myyear & "年" & mymonth & "月度"

End Function

年度を求めるコード

引数:日付
戻値:計上年度。1~3月は前年度です。

Function get_getnendo(mydate As Date) As String

    Dim myyear
    Dim mymonth
    Dim myday
    
    myyear = Year(mydate)
    mymonth = Month(mydate)
    myday = Day(mydate)

    If myday >= 21 Then
        mymonth = mymonth + 1
        
        If mymonth = 13 Then
            myyear = myyear + 1
        End If
      Else
    End If
    
    If mymonth <= 3 Then
        myyear = myyear - 1
    End If
    
    get_getnendo = myyear & "年度"

End Function
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?