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

I need to write a macro that copies cells in a specific row and then
loops to the next row, next row being 5 rows below.

So, copy cells C7, D7 to H7
then, Copy the next set C12, D12 ... H12
and so on.

I would assume this would be done using 2 loops, one for goings
through the columns and one for the rows, but I could be wrong.

I am not sure of the syntax, so if anyone can give me some tips, that
would be great.
Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
HI HI is offline
external usenet poster
 
Posts: 5
Default Loop to specific rows

Don't know if this is what you wanted. Following macro will add number
1 on cells C7, D7 to H7 and C12, D12 ... H12 etc.
You replace the 1 with your formula

Sub TEST()
Range("C7").Select
For i = 0 To 10
For j = 0 To 5
ActiveCell.Offset(i * 5, j).Value = 1
Next j
Next i
End Sub





On 26 syys, 16:52, Omar wrote:
I need to write a macro that copies cells in a specific row and then
loops to the next row, next row being 5 rows below.

So, copy cells C7, D7 to H7
then, Copy the next set C12, D12 ... H12
and so on.

I would assume this would be done using 2 loops, one for goings
through the columns and one for the rows, but I could be wrong.

I am not sure of the syntax, so if anyone can give me some tips, that
would be great.
Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Loop to specific rows

On Sep 26, 10:01 am, HI wrote:
Don't know if this is what you wanted. Following macro will add number
1 on cells C7, D7 to H7 and C12, D12 ... H12 etc.
You replace the 1 with your formula

Sub TEST()
Range("C7").Select
For i = 0 To 10
For j = 0 To 5
ActiveCell.Offset(i * 5, j).Value = 1
Next j
Next i
End Sub



Thanks, that makes sense.

I had another question
my original formula was just extracting the first 3 chars from a
specific cell, now as I have to loop through the columns and rows, the
following won't work:
id = Range("C7").Characters(1, 3).Text

Using you method, how would I integrate this into the code?

ActiveCell.Offset(i * 5, j).Value = 1 is inserting '1' into those
cells. How do I make it copy those cells instead?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Loop to specific rows

I am tying the following, but it doesn't seem to work

Range("B7").Select
For i = 0 To 10
For j = 0 To 6
ActiveCell.Offset(i * 5, j).Select
Selection.Copy

Windows("Test.xls").Activate
ActiveCell.Range("A2").Select
ActiveSheet.Paste

Next j
Next i

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Loop to specific rows

Run from the sheet with the source data and change sheet27 to suit
sub copyevery7()
With Sheets("sheet27")
..Columns("H:z").Delete
For i = 7 To Cells(Rows.Count, "c").End(xlUp).Row Step 7
lr = .Cells(Rows.Count, "H").End(xlUp).Row + 1
Cells(i, "c").Resize(, 4).Copy .Cells(lr, "h")
Next i
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Omar" wrote in message
ps.com...
I am tying the following, but it doesn't seem to work

Range("B7").Select
For i = 0 To 10
For j = 0 To 6
ActiveCell.Offset(i * 5, j).Select
Selection.Copy

Windows("Test.xls").Activate
ActiveCell.Range("A2").Select
ActiveSheet.Paste

Next j
Next i




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Loop to specific rows

Didn't notice the part about another file. Try this from the source workbook
& sheet if BOTH open.

Sub copyevery7()
With Workbooks("test.xls").Sheets("sheet1")
..Columns("H:z").Delete
For i = 7 To Cells(Rows.Count, "c").End(xlUp).Row Step 7
lr = .Cells(Rows.Count, "H").End(xlUp).Row + 1
Cells(i, "c").Resize(, 4).Copy .Cells(lr, "h")
Next i
End With
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
Run from the sheet with the source data and change sheet27 to suit
sub copyevery7()
With Sheets("sheet27")
.Columns("H:z").Delete
For i = 7 To Cells(Rows.Count, "c").End(xlUp).Row Step 7
lr = .Cells(Rows.Count, "H").End(xlUp).Row + 1
Cells(i, "c").Resize(, 4).Copy .Cells(lr, "h")
Next i
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Omar" wrote in message
ps.com...
I am tying the following, but it doesn't seem to work

Range("B7").Select
For i = 0 To 10
For j = 0 To 6
ActiveCell.Offset(i * 5, j).Select
Selection.Copy

Windows("Test.xls").Activate
ActiveCell.Range("A2").Select
ActiveSheet.Paste

Next j
Next i



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
Counting characters in multiple rows when rows meet specific criteria news.virginmedia.com Excel Worksheet Functions 3 June 28th 08 09:03 PM
Loop thru lines of text in a cell and extract specific values: please help? Mslady[_23_] Excel Programming 2 April 3rd 06 03:22 PM
Exclude specific wks in FOR EACH wks Loop Dean Excel Programming 4 December 14th 05 06:19 PM
Loop through specific worksheets Ben Excel Programming 4 November 27th 05 02:37 PM
Macro/Loop If Statement Help -delete the row with the specific te Bricktop Excel Programming 5 October 28th 05 09:50 PM


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