PC Review


Reply
Thread Tools Rate Thread

activecell.offset question

 
 
SteveDB1
Guest
Posts: n/a
 
      1st Mar 2008
Hi all.
I'm tinkering with an idea for a macro and was able to create the following.
-----------------
For i = 0 To 30
Selection.Copy
ActiveCell.Offset(rowoffset:=4, columnoffset:=0).Activate
ActiveSheet.Paste
Next i
End
--------------------
It's supposed to copy an initial merged cell with contents, and then jump
down to the next merged cell group (each merged cell group is 2 rows, 1
column).
It runs for 30 iterations, and then stops.
When I tried it I noticed that starting with row 25, it jumps one row, does
the two row paste, jumps a row, does two, etc... out to the 30 iteration end.
i.e.,
copy rows 1/2, jumps two rows, pastes 5/6, jumps to 9/10 & pastes, jumps two
rows & pastes... etc.. out to rows 21/22. Then at row 25, it jumps over that,
and pastes every 5th row.
What have I done wrong?
The code you see above is exactly what I'm running.

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      1st Mar 2008
Working with merged cells is a little tricky. Here is an example
of how to walk it down the range. Using the select and activate
will cause you problems. You can use the i variable to set your
row numbers for the range you want to cover and specify the
column as I have done below. Then use the offset. bearing in
mind that the numbers in parentheses count from the specified
range down and right for positive numbers and up and left for
negative numbers. The step 2 causes it to only execute on the
merged cell one time. You will need to modify this to meet your
needs.

Sub luptst()
For i = 1 To 8 Step 2
Range("A" & i).Copy
Range("A" & i).Offset(4, 1).PasteSpecial Paste:=xlPasteValues
Next
End Sub

"SteveDB1" wrote:

> Hi all.
> I'm tinkering with an idea for a macro and was able to create the following.
> -----------------
> For i = 0 To 30
> Selection.Copy
> ActiveCell.Offset(rowoffset:=4, columnoffset:=0).Activate
> ActiveSheet.Paste
> Next i
> End
> --------------------
> It's supposed to copy an initial merged cell with contents, and then jump
> down to the next merged cell group (each merged cell group is 2 rows, 1
> column).
> It runs for 30 iterations, and then stops.
> When I tried it I noticed that starting with row 25, it jumps one row, does
> the two row paste, jumps a row, does two, etc... out to the 30 iteration end.
> i.e.,
> copy rows 1/2, jumps two rows, pastes 5/6, jumps to 9/10 & pastes, jumps two
> rows & pastes... etc.. out to rows 21/22. Then at row 25, it jumps over that,
> and pastes every 5th row.
> What have I done wrong?
> The code you see above is exactly what I'm running.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ActiveCell.Offset Question ash3154 Microsoft Excel New Users 3 12th Sep 2009 01:46 PM
Offset and ActiveCell Pendragon Microsoft Excel Programming 11 28th Apr 2009 11:18 PM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Microsoft Excel Misc 1 2nd Oct 2007 08:05 PM
ActiveCell Offset rnrss Microsoft Excel Programming 0 7th Oct 2005 10:12 AM
Re: ActiveCell.Offset w/ VBA Bob Umlas Microsoft Excel Programming 2 4th Sep 2004 02:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 PM.