Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Loop syntax help

Access 2007 on Vista

The Excel macro recorder provided the three sample blocks of code (almost
identical you can see, but pattern flow should be noted) which I need to code
into a single block to repeat "n" times based on cell "D17". I know where I
am, I know where I want to get to, I just don't know the way to get there.
Many thanks in advance.


i = 1
Filler = Range("D17").Value

Do While i < Filler

Sheets("Sample Data").Select
Range("B3:E3").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C21").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B4:E4").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C22").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B5:E5").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C23").Select
ActiveSheet.Paste

i = i + 1
Loop

The syntax to have this puppy perform is what I an needing.

Thanks ....TheGrapeHunter
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Loop syntax help

i = 1
Filler = Range("D17").Value
Do While i < Filler

Sheets("Sample Data").Select
Range("B" & (i + 2) & ":E" & (i + 2)).Select
Selection.Copy
Sheets("Sheet1").Select
Range("C" & (i + 20)).Select
ActiveSheet.Paste

i = i + 1
Loop

If this post helps click Yes
---------------
Jacob Skaria


"The Grape Hunter" wrote:

Access 2007 on Vista

The Excel macro recorder provided the three sample blocks of code (almost
identical you can see, but pattern flow should be noted) which I need to code
into a single block to repeat "n" times based on cell "D17". I know where I
am, I know where I want to get to, I just don't know the way to get there.
Many thanks in advance.


i = 1
Filler = Range("D17").Value

Do While i < Filler

Sheets("Sample Data").Select
Range("B3:E3").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C21").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B4:E4").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C22").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B5:E5").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C23").Select
ActiveSheet.Paste

i = i + 1
Loop

The syntax to have this puppy perform is what I an needing.

Thanks ....TheGrapeHunter

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Loop syntax help

Shorter:

i = 1
Filler = Range("D17").Value
Do While i < Filler
Sheets("Sample Data").Range("B" & (i + 2) & ":E" & (i + 2)).Copy _
Sheets("Sheet1"). Range("C" & (i + 20))
i = i + 1
Loop

Typically it's best to avoid select/activate unless you really need it.

Tim



"Jacob Skaria" wrote in message
...
i = 1
Filler = Range("D17").Value
Do While i < Filler

Sheets("Sample Data").Select
Range("B" & (i + 2) & ":E" & (i + 2)).Select
Selection.Copy
Sheets("Sheet1").Select
Range("C" & (i + 20)).Select
ActiveSheet.Paste

i = i + 1
Loop

If this post helps click Yes
---------------
Jacob Skaria


"The Grape Hunter" wrote:

Access 2007 on Vista

The Excel macro recorder provided the three sample blocks of code (almost
identical you can see, but pattern flow should be noted) which I need to
code
into a single block to repeat "n" times based on cell "D17". I know where
I
am, I know where I want to get to, I just don't know the way to get
there.
Many thanks in advance.


i = 1
Filler = Range("D17").Value

Do While i < Filler

Sheets("Sample Data").Select
Range("B3:E3").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C21").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B4:E4").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C22").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B5:E5").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C23").Select
ActiveSheet.Paste

i = i + 1
Loop

The syntax to have this puppy perform is what I an needing.

Thanks ....TheGrapeHunter



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Loop syntax help

And, without the loop...

With Worksheets("Sample Data")
Filler = .Range("D17").Value
.Range("B3").Resize(Filler, 4).Copy Worksheets("Sheet1").Range("C21")
End With

It wasn't clear from the OP's post which worksheet D17 was on, so I assumed
it was on the "Sample Data" sheet... that can be corrected as necessary.

--
Rick (MVP - Excel)


"Tim Williams" wrote in message
...
Shorter:

i = 1
Filler = Range("D17").Value
Do While i < Filler
Sheets("Sample Data").Range("B" & (i + 2) & ":E" & (i + 2)).Copy _
Sheets("Sheet1"). Range("C" & (i + 20))
i = i + 1
Loop

Typically it's best to avoid select/activate unless you really need it.

Tim



"Jacob Skaria" wrote in message
...
i = 1
Filler = Range("D17").Value
Do While i < Filler

Sheets("Sample Data").Select
Range("B" & (i + 2) & ":E" & (i + 2)).Select
Selection.Copy
Sheets("Sheet1").Select
Range("C" & (i + 20)).Select
ActiveSheet.Paste

i = i + 1
Loop

If this post helps click Yes
---------------
Jacob Skaria


"The Grape Hunter" wrote:

Access 2007 on Vista

The Excel macro recorder provided the three sample blocks of code
(almost
identical you can see, but pattern flow should be noted) which I need to
code
into a single block to repeat "n" times based on cell "D17". I know
where I
am, I know where I want to get to, I just don't know the way to get
there.
Many thanks in advance.


i = 1
Filler = Range("D17").Value

Do While i < Filler

Sheets("Sample Data").Select
Range("B3:E3").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C21").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B4:E4").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C22").Select
ActiveSheet.Paste

Sheets("Sample Data").Select
Range("B5:E5").Select
Selection.Copy
Sheets("Sheet1").Select
Range("C23").Select
ActiveSheet.Paste

i = i + 1
Loop

The syntax to have this puppy perform is what I an needing.

Thanks ....TheGrapeHunter




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
Syntax for stopping a Do Loop? bondjel Excel Discussion (Misc queries) 5 March 22nd 10 01:35 PM
Need some syntax help, simple loop I think Mr B[_2_] Excel Programming 4 March 26th 08 01:11 PM
Do...Loop syntax help? DB74 Excel Programming 5 September 4th 07 07:04 PM
VBA Loop Case..If syntax okelly[_5_] Excel Programming 5 August 7th 06 03:24 PM
loop syntax Knox Excel Programming 2 May 17th 06 06:57 PM


All times are GMT +1. The time now is 09:58 AM.

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"