-1

如何将我的 Excel 电子表格的单元格 B4 中的以下数据:“1 天 23 小时 11 分钟”转换为可以运行数据透视表和图表的数字?

理想情况下,我想从头开始,只处理小时和天,并产生一个值(小时)。

1 天 = 8 小时工作日

谢谢

CSC

4

3 回答 3

3

这是一个VBA方法。如果您不想要 VBA 方法,请告诉我,我会删除它。

将此代码放在一个模块中。此代码考虑了和之间的所有days/day匹配hrs/hr

代码

Function ConvertToHours(rng As Range) As Long
    Dim DAr() As String, HAr() As String, strVal As String
    Dim D As Long, H As Long

    If rng Is Nothing Then
        ConvertToHours = 0
    Else
        strVal = LCase(rng.Value)

        If InStr(1, strVal, "days", vbTextCompare) Then
            DAr = Split(strVal, "days")
            D = Val(Trim(DAr(0)))

            If InStr(1, strVal, "hrs", vbTextCompare) Then
                HAr = Split(DAr(1), "hrs")
                H = Val(Trim(HAr(0)))
            ElseIf InStr(1, strVal, "hr", vbTextCompare) Then
                HAr = Split(DAr(1), "hr")
                H = Val(Trim(HAr(0)))
            End If
        ElseIf InStr(1, strVal, "day", vbTextCompare) Then
            DAr = Split(strVal, "day")
            D = Val(Trim(DAr(0)))

            If InStr(1, strVal, "hrs", vbTextCompare) Then
                HAr = Split(DAr(1), "hrs")
                H = Val(Trim(HAr(0)))
            ElseIf InStr(1, strVal, "hr", vbTextCompare) Then
                HAr = Split(DAr(1), "hr")
                H = Val(Trim(HAr(0)))
            End If
        End If

        ConvertToHours = (D * 8) + H
    End If
End Function

截屏

在此处输入图像描述

于 2013-04-30T21:05:12.283 回答
2

Try this formula to get hours as a decimal

=SUM(MID(0&A1,FIND({"d","h","m"},A1)-2,2)*{480,60,1})/60

assumes that days, hrs and mins will all be present - works for up to 99 days

If you don't care about the minutes then you can use just

=SUM(MID(0&A1,FIND({"d","h"},A1)-2,2)*{8,1})

于 2013-04-30T21:29:57.217 回答
0

试试 WORKDAY 功能。如果单击单元格并输入 =WORKDAY(8,1),它应该会告诉您所需的信息。希望能帮助到你!

于 2013-04-30T20:56:55.560 回答