Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Three lines of code that I can't understand

Hi,

I'm having trouble with my code. It works when I step through it but not
otherwise.
So I'm trouble shooting the references with Debug.Print.

Heres a couple of lines that I find inexplicable. They are right ontop of
each other as I've put them below:

Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address

The results in the immediates window are "starting $A$5" for both
debug.print lines which is as expected.
However when running it it makes $a$6 red in colour. When stepping through
it makes $a$5 red in color.

How could the reference change from one line to another. The code is in a
module if thats pertinent.

I'm totally confused as to how this could be possible

Any guidance would be greatly appreciated

Thanks
Suzanne
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Three lines of code that I can't understand

Hello,

I cannot repeat this:
Option Explicit
Sub test()
Dim theStartingCell As Range
Set theStartingCell = Range("A5")
Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address
End Sub

Do you have any event routines enabled?

Regards,
Bernd

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Three lines of code that I can't understand

I think people would have to see the whole procedure to see where there
might be a problem. Paricularly how you set variable cell refernece
theStartingCell and how you determine what to set it to. That is more than
likely where the problem lies.

You say the code is in a module, but what type of module - sheet module,
general/standard module, what?

--
Regards,
Tom Ogilvy


"Grd" wrote in message
...
Hi,

I'm having trouble with my code. It works when I step through it but not
otherwise.
So I'm trouble shooting the references with Debug.Print.

Heres a couple of lines that I find inexplicable. They are right ontop of
each other as I've put them below:

Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address

The results in the immediates window are "starting $A$5" for both
debug.print lines which is as expected.
However when running it it makes $a$6 red in colour. When stepping through
it makes $a$5 red in color.

How could the reference change from one line to another. The code is in a
module if thats pertinent.

I'm totally confused as to how this could be possible

Any guidance would be greatly appreciated

Thanks
Suzanne



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Three lines of code that I can't understand

On Feb 10, 8:52 pm, Grd wrote:

Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address


Hi,

I can't find anything wrong with your code, but nobody is
perfect. .... Is your theStartingCell the range object (the cell)?

for me the following code works fine:

' Create a yellow interior for cell A5.
Range("A5").Select
With Selection.Interior
'.ColorIndex = 6
' or
.Color = vbYellow
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range("A1").Select
MsgBox "Cell A5 has a yellow interior."

Compare the "Color Property" and "Interior Property" help and check if
the interior property is available to your object theStartingCell.

I hope it helps.

  #5   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Three lines of code that I can't understand

Hi,

I think I have found out the problem and why I'm so confused.
The startingcell that I refer to is where I'm brining in some data using
MSQuery.
Using activesheet.querytables.add.

Now immediately after bringing in the data I'm trying to figure out where
the end of the data is. I keep getting into trouble here as I can't seem to
locate it. Using things like the usedrange.rows.count and
selection.end(xldown).select etc seen to send me the wrong info.

I did a debug.print on startingcell.value and found the following
ExternalData_1: Getting Data ...

Meaning that it hadn't yet got the data before I'm onto the next line of
code trying to find the end of that data. Thats why it was working when I was
stepping into it as I was giving it enough time to bring in the data. It
wasn't an issue of referening to the wrong cells or sheets.

So my problem is now how do I give MSQuery enough time to execute before I
go looking for the end of the data.

I tried application.wait (for a second) but that just suspends the bringing
in of the data.

Thanks very much for your help on this

Suzanne

"Tom Ogilvy" wrote:

I think people would have to see the whole procedure to see where there
might be a problem. Paricularly how you set variable cell refernece
theStartingCell and how you determine what to set it to. That is more than
likely where the problem lies.

You say the code is in a module, but what type of module - sheet module,
general/standard module, what?

--
Regards,
Tom Ogilvy


"Grd" wrote in message
...
Hi,

I'm having trouble with my code. It works when I step through it but not
otherwise.
So I'm trouble shooting the references with Debug.Print.

Heres a couple of lines that I find inexplicable. They are right ontop of
each other as I've put them below:

Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address

The results in the immediates window are "starting $A$5" for both
debug.print lines which is as expected.
However when running it it makes $a$6 red in colour. When stepping through
it makes $a$5 red in color.

How could the reference change from one line to another. The code is in a
module if thats pertinent.

I'm totally confused as to how this could be possible

Any guidance would be greatly appreciated

Thanks
Suzanne






  #6   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Three lines of code that I can't understand

Hi Bernd,

Thanks for your help.
I figured out the source of my confusion.
See my answer to TOms email

Thanks
Suzanne

"Bernd" wrote:

Hello,

I cannot repeat this:
Option Explicit
Sub test()
Dim theStartingCell As Range
Set theStartingCell = Range("A5")
Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address
End Sub

Do you have any event routines enabled?

Regards,
Bernd


  #7   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Three lines of code that I can't understand

Hi Riso,

Thanks but I think I figured it out.
I explained this in my reply to Tom's email.

Thanks again
S

"riso" wrote:

On Feb 10, 8:52 pm, Grd wrote:

Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address


Hi,

I can't find anything wrong with your code, but nobody is
perfect. .... Is your theStartingCell the range object (the cell)?

for me the following code works fine:

' Create a yellow interior for cell A5.
Range("A5").Select
With Selection.Interior
'.ColorIndex = 6
' or
.Color = vbYellow
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range("A1").Select
MsgBox "Cell A5 has a yellow interior."

Compare the "Color Property" and "Interior Property" help and check if
the interior property is available to your object theStartingCell.

I hope it helps.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Three lines of code that I can't understand

This is usually caused because you have the BackGroundQuery property of the
querytable set to True. You need to set it to false and you code will wait
for the query to complete. If you record a macro it usually looks
something like

With Activesheet.QueryTables.Add( . . . )
' then a bunch of properties

one of the properties should be BackGroundQuery

--
regards,
Tom Ogilvy


"Grd" wrote in message
...
Hi,

I think I have found out the problem and why I'm so confused.
The startingcell that I refer to is where I'm brining in some data using
MSQuery.
Using activesheet.querytables.add.

Now immediately after bringing in the data I'm trying to figure out where
the end of the data is. I keep getting into trouble here as I can't seem
to
locate it. Using things like the usedrange.rows.count and
selection.end(xldown).select etc seen to send me the wrong info.

I did a debug.print on startingcell.value and found the following
ExternalData_1: Getting Data ...

Meaning that it hadn't yet got the data before I'm onto the next line of
code trying to find the end of that data. Thats why it was working when I
was
stepping into it as I was giving it enough time to bring in the data. It
wasn't an issue of referening to the wrong cells or sheets.

So my problem is now how do I give MSQuery enough time to execute before I
go looking for the end of the data.

I tried application.wait (for a second) but that just suspends the
bringing
in of the data.

Thanks very much for your help on this

Suzanne

"Tom Ogilvy" wrote:

I think people would have to see the whole procedure to see where there
might be a problem. Paricularly how you set variable cell refernece
theStartingCell and how you determine what to set it to. That is more
than
likely where the problem lies.

You say the code is in a module, but what type of module - sheet module,
general/standard module, what?

--
Regards,
Tom Ogilvy


"Grd" wrote in message
...
Hi,

I'm having trouble with my code. It works when I step through it but
not
otherwise.
So I'm trouble shooting the references with Debug.Print.

Heres a couple of lines that I find inexplicable. They are right ontop
of
each other as I've put them below:

Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address

The results in the immediates window are "starting $A$5" for both
debug.print lines which is as expected.
However when running it it makes $a$6 red in colour. When stepping
through
it makes $a$5 red in color.

How could the reference change from one line to another. The code is in
a
module if thats pertinent.

I'm totally confused as to how this could be possible

Any guidance would be greatly appreciated

Thanks
Suzanne






  #9   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Three lines of code that I can't understand

Immediately solved the problem

Thanks
S

"Tom Ogilvy" wrote:

This is usually caused because you have the BackGroundQuery property of the
querytable set to True. You need to set it to false and you code will wait
for the query to complete. If you record a macro it usually looks
something like

With Activesheet.QueryTables.Add( . . . )
' then a bunch of properties

one of the properties should be BackGroundQuery

--
regards,
Tom Ogilvy


"Grd" wrote in message
...
Hi,

I think I have found out the problem and why I'm so confused.
The startingcell that I refer to is where I'm brining in some data using
MSQuery.
Using activesheet.querytables.add.

Now immediately after bringing in the data I'm trying to figure out where
the end of the data is. I keep getting into trouble here as I can't seem
to
locate it. Using things like the usedrange.rows.count and
selection.end(xldown).select etc seen to send me the wrong info.

I did a debug.print on startingcell.value and found the following
ExternalData_1: Getting Data ...

Meaning that it hadn't yet got the data before I'm onto the next line of
code trying to find the end of that data. Thats why it was working when I
was
stepping into it as I was giving it enough time to bring in the data. It
wasn't an issue of referening to the wrong cells or sheets.

So my problem is now how do I give MSQuery enough time to execute before I
go looking for the end of the data.

I tried application.wait (for a second) but that just suspends the
bringing
in of the data.

Thanks very much for your help on this

Suzanne

"Tom Ogilvy" wrote:

I think people would have to see the whole procedure to see where there
might be a problem. Paricularly how you set variable cell refernece
theStartingCell and how you determine what to set it to. That is more
than
likely where the problem lies.

You say the code is in a module, but what type of module - sheet module,
general/standard module, what?

--
Regards,
Tom Ogilvy


"Grd" wrote in message
...
Hi,

I'm having trouble with my code. It works when I step through it but
not
otherwise.
So I'm trouble shooting the references with Debug.Print.

Heres a couple of lines that I find inexplicable. They are right ontop
of
each other as I've put them below:

Debug.Print "starting " & theStartingCell.Address
theStartingCell.Interior.Color = vbRed
Debug.Print "starting " & theStartingCell.Address

The results in the immediates window are "starting $A$5" for both
debug.print lines which is as expected.
However when running it it makes $a$6 red in colour. When stepping
through
it makes $a$5 red in color.

How could the reference change from one line to another. The code is in
a
module if thats pertinent.

I'm totally confused as to how this could be possible

Any guidance would be greatly appreciated

Thanks
Suzanne






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to understand "IF" code nascarjc New Users to Excel 3 January 31st 06 06:16 PM
How to see how many lines of code ? SpookiePower Excel Programming 3 January 25th 06 03:01 AM
Help me understand this code Carrot Excel Discussion (Misc queries) 2 October 14th 05 06:07 AM
Code to write out all lines of code davidm Excel Programming 3 August 5th 05 04:26 AM
Lines fo code Neeraja[_2_] Excel Programming 2 October 16th 03 01:07 PM


All times are GMT +1. The time now is 08:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"