Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Eden Jones   on Oct 07 In MS Office Category.

  
Question Answered By: Ismet Yilmaz   on Oct 07

Let me first see if I understand what you're trying to do, step
by step, ok?

If I understood you, you might be updating  the other rows besides
the inserted onese, so you can do that first. That is, copy  and
paste or transfer  otherwise, the updated data  from rows B2 to B540,
as well as the rows that MIGHT follow the insert,if that's relevant;

THEN IF the value in "B541" doesNOT match the value in "B2",
then you want to insert  the cells from "A541:Q560" on the first
sheet to the second sheet;

On the other hand, if the value in "B541" DOES match the value
in "B2", then you want to COPY OVER the cells on the second sheet
with the values from "A541:Q560" on the first sheet.

If that is the task, then, why not take the steps of comparing
those values first? Or, at least find out the values of B2 and B541
and put them into variables first to be compared as needed.

Then, count the rows from A541 to the last row of the data you
need to transfer . . . a simple loop could do that. That way, you
don't have to worry about how many rows you're inserting . . . it
would be the exact number of rows.

Then you can, check the values in B2 and B541 and compare them to
see it they match.

If they do, then you can write the code  for the COPY OVER version
of the data transfer, then exit that sub after that portion of code.

If they DON'T match, then you can do a GOTO to skip over the
COPY OVER version of the data transfer and then set  up the beginning
of the INSERT ROW-DATA at that GOTO point, labeling it in a way that
you like.

Looking at the code you have below, it looks like to me that
you're trying to do too much at once. It might be possible to do it
that way, but taking it step-wise might help  solve the problem until
you see a better way.

After all, if I understood you, you're only moving about 20 rows
of data, from column A to Q . . . which isn't all that much, so it
should be very fast to do. If you were moving 20,000 rows, then it
might take a bit more to figure out the exact parameters.

You might also do use the macro recorder and manually do each
of the steps and look at the code that the editor generates.

Also, you might consider moving the exact values, using the
paste-value version of the copy-paste . . . and then fill down the
formulas if they are the same in each column, or add them back in
with code. That should take most, if not all, of the #REF errors
out--you'd be copying the raw data and then using new formulas.

Also, remember that the formulas can be written in R1C1 format
which is much easier to transfer across sheets in the first place.

Hope those ideas help a bit, and please clarify, if I've missed
something, or misunderstood your task.

Share: 

 

This Question has 8 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Copy_To_Another_Workbook Or get search suggestion and latest updates.