D
darlove
Hi all. I have a little problem. It will be hard to explain but I'll
try my best. I've been writing some mini-application in VBA in Excel.
One of the bricks is a table that I have to format. When I am
debugging my code, that is I step through it one line at a time, after
some lines the degugger stops suddenly. The yellow line is
disappearing and I can't go any further. I get no message. No error.
Just stops and that's it. This seems to be happening quite at random,
as far as I have noticed. To give you an idea... I have a custom
object that represents the table. It has some methods that enable me
to manipulate the table. When I want to change headers to some
predefined ones that are being held in a defined range on a settings
sheet, the debugger sometimes stops. This is the code:
This is one of the methods of the custom object that
allows me to change the headers in the table.
Public Sub setFinalHeaders()
Dim rOldHeaders As Range
Dim rFinalHeaders As Range
' This variable will hold the headers
' to be transferred to the exported sheet.
Dim vFinalHeaders As Variant
Dim k As Byte
Dim bytHeaderCount As Byte
' Get the range from the settings spreadsheet.
' Remember that the range is spanning the whole row
' so we need to tailor it to the actual number of
' headers.
Set rFinalHeaders = Me.SettingsWsht.Range("final_headers")
' Get the number of adjacent non-empty cells.
bytHeaderCount =
Application.WorksheetFunction.CountA(rFinalHeaders)
' Get the range with non-empty cells (headers).
Set rFinalHeaders =
rFinalHeaders.Resize(ColumnSize:=bytHeaderCount)
' Transfer the headers to a variant array.
vFinalHeaders = rFinalHeaders
' Get the actual headers on the exported spreadsheet.
Set rOldHeaders = Me.Headers
' MARKED FOR THE PURPOSE OF THIS POST. -------------------
' Transfer the final headers to the exported sheet.
rOldHeaders = vFinalHeaders
'
------------------------------------------------------------------------------------------
' Now, indicate that the headers have been changed.
' This line must appear immediately after the previous one.
' TODO When it's all done, change the Visible to False so that
' the name is not visible in any dialog boxes.
Me.TheWorksheet.Names.Add Name:="table_ready", RefersToR1C1:="=1",
Visible:=True
' Clean up.
Set rFinalHeaders = Nothing
Set rOldHeaders = Nothing
End Sub
The problem is that, when in degbug mode, I get to the line that I
HAVE MARKED
try my best. I've been writing some mini-application in VBA in Excel.
One of the bricks is a table that I have to format. When I am
debugging my code, that is I step through it one line at a time, after
some lines the degugger stops suddenly. The yellow line is
disappearing and I can't go any further. I get no message. No error.
Just stops and that's it. This seems to be happening quite at random,
as far as I have noticed. To give you an idea... I have a custom
object that represents the table. It has some methods that enable me
to manipulate the table. When I want to change headers to some
predefined ones that are being held in a defined range on a settings
sheet, the debugger sometimes stops. This is the code:
This is one of the methods of the custom object that
allows me to change the headers in the table.
Public Sub setFinalHeaders()
Dim rOldHeaders As Range
Dim rFinalHeaders As Range
' This variable will hold the headers
' to be transferred to the exported sheet.
Dim vFinalHeaders As Variant
Dim k As Byte
Dim bytHeaderCount As Byte
' Get the range from the settings spreadsheet.
' Remember that the range is spanning the whole row
' so we need to tailor it to the actual number of
' headers.
Set rFinalHeaders = Me.SettingsWsht.Range("final_headers")
' Get the number of adjacent non-empty cells.
bytHeaderCount =
Application.WorksheetFunction.CountA(rFinalHeaders)
' Get the range with non-empty cells (headers).
Set rFinalHeaders =
rFinalHeaders.Resize(ColumnSize:=bytHeaderCount)
' Transfer the headers to a variant array.
vFinalHeaders = rFinalHeaders
' Get the actual headers on the exported spreadsheet.
Set rOldHeaders = Me.Headers
' MARKED FOR THE PURPOSE OF THIS POST. -------------------
' Transfer the final headers to the exported sheet.
rOldHeaders = vFinalHeaders
'
------------------------------------------------------------------------------------------
' Now, indicate that the headers have been changed.
' This line must appear immediately after the previous one.
' TODO When it's all done, change the Visible to False so that
' the name is not visible in any dialog boxes.
Me.TheWorksheet.Names.Add Name:="table_ready", RefersToR1C1:="=1",
Visible:=True
' Clean up.
Set rFinalHeaders = Nothing
Set rOldHeaders = Nothing
End Sub
The problem is that, when in degbug mode, I get to the line that I
HAVE MARKED