Debugging suddenly stops...

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
 
J

Jim Cone

If you add "Option Explicit" as the first line in your module,
I believe you will be able to find some of the problems.
 
D

darlove

If you add "Option Explicit" as the first line in your module,
I believe you will be able to find some of the problems.

Well, it does not solve the problem because I have Option Explicit
ALWAYS ON. I have never programmed without it.

Darlove
 
S

Susan

i had a somewhat similar problem & tom (i believe) told me to change
my vba editor options from "break on unhandled errors" to "break in
class module."
maybe that will help you?
hth
susan
 
D

darlove

Thanx for the advice... I have solved the problem but to tell you how
is not possible.
I just do not know how I did. I must have done something to Excel but
can't figure
out what that was. Sorry :(

Darek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top