the grand finale:这段VBA程序出现“运行时错误 424”的问题,请帮忙,谢谢!

来源:百度文库 编辑:高考问答 时间:2024/05/15 01:57:32
这段VBA程序,用Call SetMonthSum(Month, 7, "2005-12")调用的时候会出现“运行时错误 424”的问题,请帮忙,谢谢!
Public Function GetEndRow(ByVal sht As Worksheet, ByVal RowBegin As Integer, ByVal ColumnIndex As Integer)
Dim RowIndex As Integer
RowIndex = RowBegin
While CStr(sht.Cells(RowIndex, ColumnIndex).Value) <> ""
RowIndex = RowIndex + 1
Wend
GetEndRow = RowIndex - 1
End Function
Public Function GetSumMonth(ByVal sht As Worksheet, ByVal RowBegin As Integer, ByVal ColumnIndex As Integer, _
ByVal RefColumn As Integer, ByVal Str As String) As Double
Dim RowIndex As Integer
Dim RowEnd As Integer
Dim Sum As Double
RowEnd = GetEndRow(sht, RowBegin, RefColumn)
Sum = 0
For RowIndex = RowBegin To RowEnd
If Mid(sht.Cells(RowIndex, RefColumn), 1, 7) = Str Then
Sum = Sum + sht.Cells(RowIndex, ColumnIndex).Value
End If
Next
GetSumMonth = Sum
End Function
Public Sub SetMonthSum(ByVal sht As Worksheet, ByVal Row As Integer, ByVal MonthStr As String)
Dim MonthSum As Double
Dim MonthSumEat As Double
Dim MonthSumHousing As Double
Dim MonthSumComunication As Double
Dim MonthSumOther As Double
MonthSumEat = GetSumMonth(Eat, 6, 8, 1, MonthStr)
MonthSumHousing = GetSumMonth(Housing, 6, 7, 1, MonthStr)
MonthSumComunication = GetSumMonth(Comunication, 6, 4, 1, MonthStr)
MonthSumOther = GetSumMonth(Other, 6, 6, 1, MonthStr)
MonthSum = MonthSumEat + MonthSumHousing + MonthSumComunication + MonthSumOther
sht.Cells(Row, 1) = MonthStr
sht.Cells(Row, 2) = MonthSumHousing