我正在编写一个代码,使用vba在excel中划分两行。我遇到了溢出错误。
Private Sub Rated_Advances_Total_Advance()
Const FOLDER As String = "C:\SBI_Files\"
Const cStrWSName As String = "Rated Advances to Total Advance"
Const sourceName As String = "Credit Risk Components"
On Error GoTo ErrorHandler
Dim i As Integer
Dim fileName As String
'ThisWorkbook.Worksheets(cStrWSName).Range("A4:C9").ClearContents
' ThisWorkbook.Worksheets(cStrWSName).Range("A12:C17").ClearContents
' ThisWorkbook.Worksheets(cStrWSName).Range("A19:C29").ClearContents
P = 4
j = 1
fileName = Dir(FOLDER, vbDirectory)
Do While Len(fileName) > 0
If Right$(fileName, 4) = "xlsx" Or Right$(fileName, 3) = "xls" Then
i = i + 1
Dim currentWkbk As Excel.Workbook
Set currentWkbk = Excel.Workbooks.Open(FOLDER & fileName)
'Entity wise consolidation'
ThisWorkbook.Worksheets(cStrWSName).Cells(P, j).Value = Left(currentWkbk.Name, Len(currentWkbk.Name) - 4)
ThisWorkbook.Worksheets(cStrWSName).Cells(P, j).Font.Bold = True
ThisWorkbook.Worksheets(cStrWSName).Cells(P, 2).Value = currentWkbk.Sheets(sourceName).Cells(24, 3).Value / currentWkbk.Sheets(sourceName).Cells(27, 3).Value
(我在这里遇到了溢出错误)
P = P + 1
currentWkbk.Close
End If
fileName = Dir
Loop
Rated_Advances_Total_Advance
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
答案 0 :(得分:0)
如果您的值大于15位,如果您尝试将其用作整数,则会导致溢出。
Dim myValue As Long
myValue = Cells(.....).Value