I'm getting a very strange 400 error that I cannot explain.
I have two sheets
Reconciliation Reporting
(Button pointing to a Sub "ThisWorkbook.ImportRawData"Trading Day Processes
, on which the import is actually happening also with a button pointing to "ThisWorkbook.ImportRawData"
When I click the button in Sheet Trading Day Processes
everything works without a problem. When the button is clicked in Sheet Reconciliation Reporting
then a 400 appears.
I have traced the error down. When I comment the part out everything works. I cannot find the reason for this 400 error, that the following part could cause.
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
The ImportRawData
sub (I have cut out the code that is not relevant for this error.
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
The Sub calls a function CreateEndOfDayRow(). I have cut out some code that is not relevant for this error (too long otherwise):
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
Maybe it has to do with the wrong use of Worksheets? As explained above when the Sub is called from within the same sheet everything works.