Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Using variables with ROWs

Is it possible to use varibles in a function such as "ROWS
(2:5).Select" (see line 70 & 80 of code below) to allow
for looping such as:

For example if SAMPLE_NUMBER=4 I want to insert the copied
cells in 3 different places.

10 For x = 1 To (Sample_Number - 1)
20 'Copy the original 4 rows
30 Rows("2:5").Select
40 Application.CutCopyMode = False
50 Selection.Copy
60 'Insert copied cells
70 y = 2 + (x * 4) 'move down four rows
80 Rows(y:y).Select 'THIS DOES NOT WORK
90 Selection.Insert Shift:=xlDown
100 'repeat this copy/paste moving 4 additional rows
each time.
110 Next x
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Using variables with ROWs

Michael,

When you copy a range and want to paste it (or insert it) you need only
designate a single cell for the paste or insert. Note that selection is not
required.

Selection.Copy
Cells(y,1).Insert

Rows("2:5").Copy
Range("A" & y).Insert Shift:=xlDown

--
sb
"Michael" wrote in message
...
Is it possible to use varibles in a function such as "ROWS
(2:5).Select" (see line 70 & 80 of code below) to allow
for looping such as:

For example if SAMPLE_NUMBER=4 I want to insert the copied
cells in 3 different places.

10 For x = 1 To (Sample_Number - 1)
20 'Copy the original 4 rows
30 Rows("2:5").Select
40 Application.CutCopyMode = False
50 Selection.Copy
60 'Insert copied cells
70 y = 2 + (x * 4) 'move down four rows
80 Rows(y:y).Select 'THIS DOES NOT WORK
90 Selection.Insert Shift:=xlDown
100 'repeat this copy/paste moving 4 additional rows
each time.
110 Next x



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
Summing rows using formulas with variables Gateway204 Excel Discussion (Misc queries) 2 October 24th 11 07:09 PM
Selecting Rows using Long Variables pallaver Excel Discussion (Misc queries) 2 July 14th 08 07:13 AM
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
More than 1 Variables [email protected] Excel Discussion (Misc queries) 1 November 29th 06 02:09 AM
Lift Data from Rows to Populate HTML Variables [email protected] Excel Discussion (Misc queries) 1 August 1st 06 01:30 PM


All times are GMT +1. The time now is 07:23 PM.

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"