different results when debugging

J

juls001

HI

I'm trying to copy some data from excel into a table in word, I loop
through the excel spreadsheet and put the data into the word table:

Do

oTable.Cell(i, 1).Range = Right(ActiveCell.Offset(0,
0).Value, 7)
oTable.Cell(i, 2).Range = ActiveCell.Offset(0, 1).Value
oTable.Cell(i, 3).Range = ActiveCell.Offset(0, 2).Value
oTable.Cell(i, 4).Range =
FormatNumber(ActiveCell.Offset(0, 3).Value, 2)

i = i + 1
ActiveCell.Offset(1, 0).Select
If IsEmpty(ActiveCell) = False Then
wrdDoc.Tables(4).Rows.Add
End If

It works fine (ie all 12 rows are copied) when I'm debugging, however
when I run it from the userform it gives me different results eg
sometimes 2 or 12 rows are there, sometimes 10 or 12 rows etc.

Can anyone help? Thanks in advance
 
J

Jim Cone

Is the same sheet active in both scenarios?
Is the active cell the same?
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"juls001" <[email protected]>
wrote in message
HI
I'm trying to copy some data from excel into a table in word, I loop
through the excel spreadsheet and put the data into the word table:
Do
oTable.Cell(i, 1).Range = Right(ActiveCell.Offset(0, 0).Value, 7)
oTable.Cell(i, 2).Range = ActiveCell.Offset(0, 1).Value
oTable.Cell(i, 3).Range = ActiveCell.Offset(0, 2).Value
oTable.Cell(i, 4).Range =
FormatNumber(ActiveCell.Offset(0, 3).Value, 2)

i = i + 1
ActiveCell.Offset(1, 0).Select
If IsEmpty(ActiveCell) = False Then
wrdDoc.Tables(4).Rows.Add
End If

It works fine (ie all 12 rows are copied) when I'm debugging, however
when I run it from the userform it gives me different results eg
sometimes 2 or 12 rows are there, sometimes 10 or 12 rows etc.
Can anyone help? Thanks in advance
 
J

juls001

Is the same sheet active in both scenarios?
Is the active cell the same?
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware

"juls001" <[email protected]>
wrote in message
HI
I'm trying to copy some data from excel into a table in word, I loop
through the excel spreadsheet and put the data into the word table:
Do
oTable.Cell(i, 1).Range = Right(ActiveCell.Offset(0, 0).Value, 7)
oTable.Cell(i, 2).Range = ActiveCell.Offset(0, 1).Value
oTable.Cell(i, 3).Range = ActiveCell.Offset(0, 2).Value
oTable.Cell(i, 4).Range =
FormatNumber(ActiveCell.Offset(0, 3).Value, 2)

i = i + 1
ActiveCell.Offset(1, 0).Select
If IsEmpty(ActiveCell) = False Then
wrdDoc.Tables(4).Rows.Add
End If

It works fine (ie all 12 rows are copied) when I'm debugging, however
when I run it from the userform it gives me different results eg
sometimes 2 or 12 rows are there, sometimes 10 or 12 rows etc.
Can anyone help? Thanks in advance

Hi Jim
Yes to both, any ideas? I thought that it might have something to do
with optimization?
Thanks
Juliette
 
J

Jean-Yves

Hi,

Try adding debuging code so you can trace in the immediate window the steps
done
debug.print "Value I " & I & "Row 1" =
Right(ActiveCell.Offset(0, 0).Value, 7)debug.print "Value I :" & i

Regards
JY
 
J

juls001

Hi,

Try adding debuging code so you can trace in the immediate window the steps
done


debug.print "Value I " & I & "Row 1" =
Right(ActiveCell.Offset(0, 0).Value, 7)>> oTable.Cell(i, 2).Range = ActiveCell.Offset(0, 1).Value

debug.print "Value I :" & i

Regards
JY







- Show quoted text -

Hi
I get what I would expect it to be writing in the table except its
not.
Thanks
Juliette
 
J

juls001

Hi
I get what I would expect it to be writing in the table except its
not.
Thanks
Juliette- Hide quoted text -

- Show quoted text -

HI
further info, if I add two message boxs at the beginning of the loop
(one shows me value of 1 and the other value of activecell) and I
therefore have keep on clicking ok it all works fine as long as I
don't click ok too quickly.....
 

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