MartinS
Active Member
- Joined
- Jun 17, 2003
- Messages
- 490
- Office Version
- 365
- Platform
- Windows
Really odd one...
I have a procedure called from a Ribbon click event, and it works except for one line which is a call (one of several) to a sub which copies data from an array into a range. Apparently you can't put a breakpoint directly on the call, but even with a breakpoint on the first line of the procedure, it never hits it, and also never errors, so the following code fails as this step isn't completing.
This is the format:
And this is that procedure which is being skipped by the code:
The variable 'gvarLVDRunTable' is a variant array that contains the data from another workbook (opened earlier in the code) and at the point of the call, it contains data, as do the other arguments. In this example, both intFinalIndex and intLVDIndex are 1.
I've never seen this happen before, and have been developing with Excel for many years, so am at a loss as to why it's happening.
Pulling the code out into a clean workbook, and restricting it to just the relevant code, it works as expected:
Any ideas?
Thanks in advance
Martin
I have a procedure called from a Ribbon click event, and it works except for one line which is a call (one of several) to a sub which copies data from an array into a range. Apparently you can't put a breakpoint directly on the call, but even with a breakpoint on the first line of the procedure, it never hits it, and also never errors, so the following code fails as this step isn't completing.
This is the format:
VBA Code:
Set rngRunTable = ThisWorkBook.Names("RunTable").RefersToRange
'Get the index of the first row
intRunCount = LBound(rngRunTable.Value, 1)
'Load the data into the run table
LoadLVDRun intFinalIndex, rngRunTable, intRunCount
VBA Code:
Private Sub LoadLVDRun(intFinalIndex As Integer, rngRunTable As Range, intLVDIndex As Integer)
Dim i As Integer
Dim varLVDEAColumns() As Variant
Const cintLVDColumns As Integer = 8
varLVDEAColumns = Array(1, 2, 3, 6, 7)
For i = LBound(varLVDEAColumns) To UBound(varLVDEAColumns) Step 1
rngRunTable.Cells(intLVDIndex, varLVDEAColumns(i)).Value = gvarLVDRunTable(intLVDIndex, varLVDEAColumns(i))
Next i
For i = cintLVDColumns To UBound(gvarLVDRunTable, 2) Step 1
rngRunTable.Cells(intLVDIndex, i).Value = gvarLVDRunTable(intFinalIndex, i)
Next i
End Sub
I've never seen this happen before, and have been developing with Excel for many years, so am at a loss as to why it's happening.
Pulling the code out into a clean workbook, and restricting it to just the relevant code, it works as expected:
VBA Code:
Dim varLVDRunTable As Variant
Sub TestProcess()
Dim intRunCount As Integer
Dim rngRunTable As Range
'Get the run table into an array
varLVDRunTable = ThisWorkbook.Names("RunTableSource").RefersToRange.Value
'Get the run table range object
Set rngRunTable = ThisWorkbook.Names("RunTableTarget").RefersToRange
'Get the index of the first row
intRunCount = LBound(rngRunTable.Value, 1)
'Load the data into the run table
LoadLVDRun 1, rngRunTable, intRunCount
End Sub
Private Sub LoadLVDRun(intFinalIndex As Integer, rngRunTable As Range, intLVDIndex As Integer)
'Declare procedure level variables
Dim i As Integer
Dim varLVDEAColumns() As Variant
'Define the columns that come from the LVD final basis row
Const cintLVDColumns As Integer = 8
'Specify the columns to copy from LVDate basis
varLVDEAColumns = Array(1, 2, 3, 6, 7)
'Populate data from the LVD final basis row
For i = LBound(varLVDEAColumns) To UBound(varLVDEAColumns) Step 1
rngRunTable.Cells(intLVDIndex, varLVDEAColumns(i)).Value = varLVDRunTable(intLVDIndex, varLVDEAColumns(i))
Next i
'Populate data from the LVD final run
For i = cintLVDColumns To UBound(varLVDRunTable, 2) Step 1
rngRunTable.Cells(intLVDIndex, i).Value = varLVDRunTable(intFinalIndex, i)
Next i
End Sub
Thanks in advance
Martin