Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JbL JbL is offline
external usenet poster
 
Posts: 17
Default VBA Code works by stepping through, not by running

Hi,

I have a macro that opens a file, reads data and performs calculations and
returns the results to a main sheet. I run through monthly files for several
years. I have been running a similar process w/o incident. For some reason
my code returns results if I Step through via F8, but not if I let it run
full steam. I get back zilch. I'm no expert, but can someone explain to me
why whatever variable assignment I have works at the slow speed but not at
normal speed? I'm really stumped since I've done similar actions many times
over and the core part of the code is the same?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Code works by stepping through, not by running


If you post your code we can comment

--
crispb
-----------------------------------------------------------------------
crispbd's Profile: http://www.excelforum.com/member.php...fo&userid=1088
View this thread: http://www.excelforum.com/showthread.php?threadid=27458

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default VBA Code works by stepping through, not by running

My guess is something to do with opening the file, does the file get opened
(time) before you try to process it? If you want to find the problem and
some break points and hit F5, then see which break points it makes it to
without error. I would start near the top and slowly move the break point
lower in the code. You may also want to watch some values to make sure you
re getting what's expected.


  #4   Report Post  
Posted to microsoft.public.excel.programming
JbL JbL is offline
external usenet poster
 
Posts: 17
Default VBA Code works by stepping through, not by running

Thank you both for responding. One of the problems is that when the file
opens, the code:

'weekly wbk with data
dataBk = sFile & edate & ".xls"

Workbooks.Open Filename:=sDir & dataBk
Workbooks(dataBk).Activate
Sheets(1).Activate

'last row of data
lRow = Range("B" & Rows.Count).End(xlUp).Row

the variable for lRow does not get the proper value. It should be 1509 in
the sample month I'm running, but comes back as 1. There is data in Col B
from Row 11 to 1509. (The 1509 can change each month, hence the bottom up
look)

Also, when the monthly file opens, it doesn't seem to become active in the
foreground - even after I tried the .activate - allowing the lRow variable to
populate.

This is really frustrating since I have done exactly the same type of
routine on other data files.

Thanks.

jbl

"HotRod" wrote:

My guess is something to do with opening the file, does the file get opened
(time) before you try to process it? If you want to find the problem and
some break points and hit F5, then see which break points it makes it to
without error. I would start near the top and slowly move the break point
lower in the code. You may also want to watch some values to make sure you
re getting what's expected.



  #5   Report Post  
Posted to microsoft.public.excel.programming
JbL JbL is offline
external usenet poster
 
Posts: 17
Default VBA Code works by stepping through, not by running

for some reason the line

Workbooks(dataBk).Activate

does not switch between books so the variables don't pick up their proper
values. Any clues? (the book is open, it just won't switch to it)


"JbL" wrote:

Hi,

I have a macro that opens a file, reads data and performs calculations and
returns the results to a main sheet. I run through monthly files for several
years. I have been running a similar process w/o incident. For some reason
my code returns results if I Step through via F8, but not if I let it run
full steam. I get back zilch. I'm no expert, but can someone explain to me
why whatever variable assignment I have works at the slow speed but not at
normal speed? I'm really stumped since I've done similar actions many times
over and the core part of the code is the same?



  #6   Report Post  
Posted to microsoft.public.excel.programming
JbL JbL is offline
external usenet poster
 
Posts: 17
Default VBA Code works by stepping through, not by running

I've noticed that if I change the Sheets(1).activate to a sheet name it
apears to work. Still checking. Any ideas?

"JbL" wrote:

for some reason the line

Workbooks(dataBk).Activate

does not switch between books so the variables don't pick up their proper
values. Any clues? (the book is open, it just won't switch to it)


"JbL" wrote:

Hi,

I have a macro that opens a file, reads data and performs calculations and
returns the results to a main sheet. I run through monthly files for several
years. I have been running a similar process w/o incident. For some reason
my code returns results if I Step through via F8, but not if I let it run
full steam. I get back zilch. I'm no expert, but can someone explain to me
why whatever variable assignment I have works at the slow speed but not at
normal speed? I'm really stumped since I've done similar actions many times
over and the core part of the code is the same?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA Code works by stepping through, not by running

I have never seen an instance of the workbook just opened not being the
active workbook. However, if it isn't, then any unqualified code pointing
to the activesheet will certainly operate on the wrong sheet.

Another problem may stem from where the code is located. Is this code
located in a sheet or the Thisworkbook module. If so, then try moving it to
a general module. If you use a button to execute it, just call from the
buttons click event rather than have the code located in the event.

--
Regards,
Tom Ogilvy


"JbL" wrote in message
...
I've noticed that if I change the Sheets(1).activate to a sheet name it
apears to work. Still checking. Any ideas?

"JbL" wrote:

for some reason the line

Workbooks(dataBk).Activate

does not switch between books so the variables don't pick up their

proper
values. Any clues? (the book is open, it just won't switch to it)


"JbL" wrote:

Hi,

I have a macro that opens a file, reads data and performs calculations

and
returns the results to a main sheet. I run through monthly files for

several
years. I have been running a similar process w/o incident. For some

reason
my code returns results if I Step through via F8, but not if I let it

run
full steam. I get back zilch. I'm no expert, but can someone explain

to me
why whatever variable assignment I have works at the slow speed but

not at
normal speed? I'm really stumped since I've done similar actions many

times
over and the core part of the code is the same?



  #8   Report Post  
Posted to microsoft.public.excel.programming
JbL JbL is offline
external usenet poster
 
Posts: 17
Default VBA Code works by stepping through, not by running

I'm not sure why this macro ended up giving me such a hard time. I changed
the sheet references from (n) to their "names" and then it worked. There
must be a disconnect somewhere in the code and I'll try to find it.

Thanks all.

jbl

"Tom Ogilvy" wrote:

I have never seen an instance of the workbook just opened not being the
active workbook. However, if it isn't, then any unqualified code pointing
to the activesheet will certainly operate on the wrong sheet.

Another problem may stem from where the code is located. Is this code
located in a sheet or the Thisworkbook module. If so, then try moving it to
a general module. If you use a button to execute it, just call from the
buttons click event rather than have the code located in the event.

--
Regards,
Tom Ogilvy


"JbL" wrote in message
...
I've noticed that if I change the Sheets(1).activate to a sheet name it
apears to work. Still checking. Any ideas?

"JbL" wrote:

for some reason the line

Workbooks(dataBk).Activate

does not switch between books so the variables don't pick up their

proper
values. Any clues? (the book is open, it just won't switch to it)


"JbL" wrote:

Hi,

I have a macro that opens a file, reads data and performs calculations

and
returns the results to a main sheet. I run through monthly files for

several
years. I have been running a similar process w/o incident. For some

reason
my code returns results if I Step through via F8, but not if I let it

run
full steam. I get back zilch. I'm no expert, but can someone explain

to me
why whatever variable assignment I have works at the slow speed but

not at
normal speed? I'm really stumped since I've done similar actions many

times
over and the core part of the code is the same?




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
Stepping through Code Jim May Excel Discussion (Misc queries) 9 October 25th 07 01:40 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 7 March 7th 05 06:29 PM
Stepping through VBA code in Excel Bill Murphy Excel Programming 2 May 14th 04 04:29 AM
Stepping through VBA code in Excel Bill Murphy Excel Programming 0 May 14th 04 02:09 AM
Stepping through code gives different results than running it! Simon White Excel Programming 2 November 13th 03 09:44 PM


All times are GMT +1. The time now is 01:37 AM.

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

About Us

"It's about Microsoft Excel"