EXCEL寫的函數

EXCEL寫的函數

// 將日期2005-02-30轉為"200502"
Function YearMonth(DateArg)
  Dim lYear, lMonth
  If DateArg = Null Or CStr(DateArg) = "" Then
    YearMonth = ""
  Else
    lYear = Year(DateArg)
    lMonth = Month(DateArg)
    YearMonth = CStr(lYear) + Right("0" + CStr(lMonth), 2)
  End If
End Function

// 將數字2030轉為"20:30"
Function ConvertToTime(Arg)
  Dim lHour, lMinute
  lHour = CStr(Left(Arg, 2))
  lMinute = CStr(Right(Arg, 2))
  If lHour > "24" Or lHour < "0" Or lMinute > "60" Or lMinute < "0" Then
    ConvertToTime = ""
  Else
    ConvertToTime = IIf(lHour = Null Or lHour = "", "", lHour + ":" + lMinute)
  End If
End Function

// 計算兩個時間的差
Function TimeDiff(BeginArg, EndArg)
  Dim lHour, lMinute
  lMinute = DateDiff("n", BeginArg, EndArg)
  lHour = Int(lMinute / 60)
  lMinute = lMinute - lHour * 60
  TimeDiff = CStr(lHour + lMinute / 60)
End Function

 

你可能感兴趣的:(EXCEL寫的函數)