Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default activecell.offset question

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default activecell.offset question

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
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
ActiveCell.Offset Question ash3154 New Users to Excel 5 September 12th 09 01:46 PM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Excel Discussion (Misc queries) 1 October 2nd 07 08:05 PM
Activecell Offset Mark Excel Programming 2 December 7th 04 04:57 PM
ActiveCell.Offset w/ VBA Bob Umlas[_3_] Excel Programming 2 September 4th 04 02:58 PM
activecell offset rvik Excel Programming 1 December 24th 03 07:47 AM


All times are GMT +1. The time now is 12:06 PM.

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"