Я получаю очень странную ошибку 400, которую не могу объяснить.
У меня есть два листа
Reconciliation Reporting
(кнопка, указывающая на подпункт «ThisWorkbook.ImportRawData» Trading Day Processes
, при котором импорт фактически выполняется также с помощью кнопки, указывающей на «ThisWorkbook.ImportRawData»
Когда я нажимаю кнопку на листе Trading Day Processes
, все работает безпроблема. При нажатии кнопки на листе Reconciliation Reporting
появляется 400.
Я отследил ошибку. Когда я закомментирую часть, все работает. Я не могу найти причину этой ошибки 400,что следующая часть может вызвать.
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeTop).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeTop).Weight = xlThick
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeBottom).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeBottom).Weight = xlThick
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeLeft).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeLeft).Weight = xlThick
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeRight).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeRight).Weight = xlThick
Sub ImportRawData
(Я вырезал код, который не имеет отношения к этой ошибке.
Sub ImportRawData()
' main function to importing from _data into Trading Day Processes
Dim Workbook As Workbook
Set Workbook = ThisWorkbook
Set tradingDaySheet = Workbook.Worksheets("Trading Day Processes")
' variable needed for importing data
Dim i As Integer
Dim m As Integer
Dim TDcurrentRow As Long
Dim DAnumDataRows As Integer
Dim MANnumDataRows As Integer
Dim TDstartRow As Long
Dim TDendRow As Integer
Dim currentDatai As Integer
' variable to check if a row was importet successfully
Dim importStatus As Boolean
' set the starting row in the Trading Day Processes Sheet
TDstartRow = 11
TDcurrentRow = TDstartRow
' get the amount of rows to import
DAnumDataRows = CountDataRows
' set the end row
TDendRow = TDstartRow + DAnumDataRows
' get the mount of rows for manual entries
MANnumDataRows = CountManualRows
' check if the sheet is clean otherwise throw message
If IsEmpty(tradingDaySheet.Range("C11").Value) = True Then
' Import Automatic processes
For i = 1 To DAnumDataRows
importStatus = ImportNextRow(i, TDcurrentRow, False)
TDcurrentRow = TDcurrentRow + 1
Next i
' Import Manual processes
For m = 1 To MANnumDataRows
importStatus = ImportNextRow(m, TDcurrentRow, True)
TDcurrentRow = TDcurrentRow + 1
Next m
' Create End of Day Balance
CreateEndOfDayRow (TDcurrentRow)
' Create P&L Sheet
'CreatePandLReporting (TDstartRow,TDcurrentRow)
Else
MsgBox "The _data sheet has not been cleared. Please clean the sheet first."
End If
MsgBox "Import Done. Happy reconciling"
End Sub
Sub вызывает функциюCreateEndOfDayRow (). Я вырезал некоторый код, который не имеет отношения к этой ошибке (слишком долго в противном случае):
Function CreateEndOfDayRow(lastRow As Long)
' The function creates the end of day balance after all intraday processes have been imported
Dim Workbook As Workbook
Set Workbook = ThisWorkbook
Set dataSheet = Workbook.Worksheets("_data")
Set tradingDaySheet = Workbook.Worksheets("Trading Day Processes")
Dim startRow As Integer
Dim startRowIncStartBalance As Integer
Dim rowDiff As Integer
startRowIncStartBalance = 10
startRow = 11
' calc difference between first and last row for automatic formulas
rowDiff = lastRow - startRow
rowDiffIncStartBalance = lastRow - startRowIncStartBalance
tradingDaySheet.Cells(lastRow, 1).Value = "EOD Balance"
tradingDaySheet.Cells(lastRow, 70).NumberFormat = FormattingModule.FormatHelper("Percentage")
===== CUT OUT CODE =======
====>The following lines seem to cause the error
' put fat boarder around balances
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeTop).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeTop).Weight = xlThick
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeBottom).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeBottom).Weight = xlThick
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeLeft).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeLeft).Weight = xlThick
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeRight).LineStyle = xlContinuous
tradingDaySheet.Range(Cells(lastRow, 1), Cells(lastRow, 70)).Borders(xlEdgeRight).Weight = xlThick
SetLastRow (lastRow)
End Function
Может быть, это связано с неправильным использованием рабочих листов? Как объяснено выше, когда Subвызывается изнутрина этом же листе все работает.