Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA-未定义子项或函数错误_Excel_Vba - Fatal编程技术网

Excel VBA-未定义子项或函数错误

Excel VBA-未定义子项或函数错误,excel,vba,Excel,Vba,我在这个方法上遇到了一个编译错误,我不知道为什么。我得到了“子函数或函数未定义”错误。这可能有点傻,但我却不在乎。 提前谢谢 Public Function GetReportDate(dept As String) As String Dim dateOut As String 'this will be the returned value from the method Dim dateIn As String 'this is the date retriev

我在这个方法上遇到了一个编译错误,我不知道为什么。我得到了“子函数或函数未定义”错误。这可能有点傻,但我却不在乎。 提前谢谢

Public Function GetReportDate(dept As String) As String

    Dim dateOut As String   'this will be the returned value from the method
    Dim dateIn As String    'this is the date retrieved from the report

    Dim MonthNum As String
    Dim Temp As String      'this variable stores that date that will be manipulated
    Dim StartEnd(1 To 4, 1 To 4) As String
    Dim Period As String
    Dim Year As Integer

    'select the date string
    Select Case dept
    Case "Min and AMF": Cells(2, 2).Select
    Case Else: Cells(2, 1).Select
    End Select

    Selection.Font.Bold = True

    'store the month, day and year string to the array
    dateIn = ActiveCell.Value
    Temp = dateIn
    StartEnd(1, 1) = Mid(Temp, 1, 2)    '1st month
    StartEnd(1, 2) = Mid(Temp, 14, 2)   '2nd month
    StartEnd(2, 1) = Mid(Temp, 4, 2)    '1st day
    StartEnd(2, 2) = Mid(Temp, 17, 2)   '2nd day
    StartEnd(3, 1) = Mid(Temp, 7, 4)    '1st year

    'assign to two var
    MonthNum = StartEnd(1, 2)
    Year = StartEnd(3, 1)

    ' change the month format for the 1st month
    Select Case StartEnd(1, 1)
        Case "01": StartEnd(1, 1) = "Jan"
        Case "02": StartEnd(1, 1) = "Feb"
        Case "03": StartEnd(1, 1) = "Mar"
        Case "04": StartEnd(1, 1) = "Apr"
        Case "05": StartEnd(1, 1) = "May"
        Case "06": StartEnd(1, 1) = "Jun"
        Case "07": StartEnd(1, 1) = "Jul"
        Case "08": StartEnd(1, 1) = "Aug"
        Case "09": StartEnd(1, 1) = "Sep"
        Case "10": StartEnd(1, 1) = "Oct"
        Case "11": StartEnd(1, 1) = "Nov"
        Case "12": StartEnd(1, 1) = "Dec"
    End Select

    ' change the month format for the 2nd month
    Select Case StartEnd(1, 2)
        Case "01": StartEnd(1, 2) = "Jan"
        Case "02": StartEnd(1, 2) = "Feb"
        Case "03": StartEnd(1, 2) = "Mar"
        Case "04": StartEnd(1, 2) = "Apr"
        Case "05": StartEnd(1, 2) = "May"
        Case "06": StartEnd(1, 2) = "Jun"
        Case "07": StartEnd(1, 2) = "Jul"
        Case "08": StartEnd(1, 2) = "Aug"
        Case "09": StartEnd(1, 2) = "Sep"
        Case "10": StartEnd(1, 2) = "Oct"
        Case "11": StartEnd(1, 2) = "Nov"
        Case "12": StartEnd(1, 2) = "Dec"
    End Select


    'Change the Date Format After the Min Qem has been executed
    'If dept = "Min and AMF" Then

        ' the 1st and 2nd month are equal
        If StartEnd(1, 1) = StartEnd(1, 2) Then
            ' find the type of report
            If StartEnd(2, 2) - StartEnd(2, 1) <= 7 Then
                Period = "Week"
            Else
                 Period = "Month"
            End If

            ' change the report period to the right format
            ActiveCell = Period & " of " & StartEnd(1, 1) & " " & StartEnd(2, 1) & " " _
                    & "to" & " " & StartEnd(2, 2) & " " & Year
        Else     ' the 1st and 2nd month are NOT equal
            If 30 - StartEnd(2, 1) + StartEnd(2, 2) >= 20 Then
                Period = "Month"
            Else
                Period = "Week"
            End If


    'change the header of the report to represt the period
                ActiveCell = Period & " of " & StartEnd(1, 1) & " " & StartEnd(2, 1) _
                        & " " & "to" & " " & StartEnd(1, 2) & " " & StartEnd(2, 2) _
                        & " " & Year
            End If

        'return the dateout
        dateOut = Temp
        GetReportDate = dateOut
    End Function

您正在调用的函数与您定义的函数不匹配<代码>日期和名称不相同

Public Function GetReportDate(dept As String) As String
        GetReportDate = dateOut
    End Function
不会有人打电话来

CurReport = GetReportName(sDept)

该死!!我是个白痴,调用了错误的函数…只是做了我告诉它要做的事情。谢谢,我刚刚注意到了同样的事情。一切都很好。
CurReport = GetReportName(sDept)