Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default constructing a copy-paste loop that skips rows

Hello. Yet another newbie question here.

I am trying to write a macro, starting with A4, copies the text in every
44th row and pastes the text into another worksheet. It should do this for
a user defined number of times. The first cell of interest is A4, the next
would then be A48, etc...

I can't figure out how to construct the loop. I have tried it using Step
(is this right?) and also using variables and Offset. I have gotten so
confused that I don't know what I am doing at this point!

Here is the mess that I have at the moment:

Sub test2()
Dim StartValue As Integer
Dim n As Integer

n = CInt(InputBox("Enter the number of inputs: "))
StartValue = 4
For Count = 1 To n Step 44
ActiveCell.Offset(StartValue, 0).Select
Selection.Copy
Sheets("Sheet2").Activate
ActiveCell(Count, 0).Select
ActiveSheet.Paste
Sheets("Sheet1").Activate
Next Count
End Sub

Any help would be much appreciated!

Thanks,

H.M.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default constructing a copy-paste loop that skips rows

Hi,

with the code as stated, the loop will terminate when
count becomes larger than n, and count will increase with
44 (the step) for each iteration of the loop.

Since you want to iterate the loop n times, it might be
easier to simply loop with step one and calculate the row
index at the start of each iteration. E.g.,

For i=1 to n
rowIndex = 44*n
...
Next i

Remember KISS: Keep It Simple Stupid! (In hardware design
also means Keep It Strictly Synchronous.) That at least
helps me every day!

Dag :) -- DagOystein.Johansen AT sage.com

-----Original Message-----
Hello. Yet another newbie question here.

I am trying to write a macro, starting with A4, copies

the text in every
44th row and pastes the text into another worksheet. It

should do this for
a user defined number of times. The first cell of

interest is A4, the next
would then be A48, etc...

I can't figure out how to construct the loop. I have

tried it using Step
(is this right?) and also using variables and Offset. I

have gotten so
confused that I don't know what I am doing at this point!

Here is the mess that I have at the moment:

Sub test2()
Dim StartValue As Integer
Dim n As Integer

n = CInt(InputBox("Enter the number of inputs: "))
StartValue = 4
For Count = 1 To n Step 44
ActiveCell.Offset(StartValue, 0).Select
Selection.Copy
Sheets("Sheet2").Activate
ActiveCell(Count, 0).Select
ActiveSheet.Paste
Sheets("Sheet1").Activate
Next Count
End Sub

Any help would be much appreciated!

Thanks,

H.M.


.

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
VBA Loop to Find then Copy & Paste B J Hankinson Excel Discussion (Misc queries) 0 April 15th 09 06:39 PM
Loop thru rows to copy to another excel spreadsheet eighthman11 Excel Worksheet Functions 0 October 9th 06 09:21 PM
Data Validation skips rows jk Setting up and Configuration of Excel 1 July 25th 06 09:15 AM
Hide Rows - copy and paste only rows that show Access101 Excel Worksheet Functions 3 March 1st 06 12:39 AM
copy,paste and loop through workbook TUNGANA KURMA RAJU Excel Discussion (Misc queries) 0 December 6th 05 12:31 PM


All times are GMT +1. The time now is 09:46 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"