View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default how do you loop through each worksheet?

try this. Modify sheet name and ranges to suit

try this. It will determine the last data in col a from the bottom up. If
you want to go down to the next use
cells(activecell.row,"a").end(xldown).row+1
It will then copy from sheet1 to all other sheets except sheet1. I suppose,
in THIS case it wouldn't be necessary to have that one excluded but.

Sub copy7on()
x = Worksheets("sheet1").Cells(Rows.Count, "a").End(xlUp).Row + 1
MsgBox x
For Each ws In Worksheets
If ws.Name < "Sheet1" Then _
Worksheets("sheet1").Cells(7, 1). _
Resize(x - 7, 3).Copy ws.Cells(7, 1)
Next
End Sub
--
Don Guillett
SalesAid Software

"dundonald" wrote in message
...
"Don Guillett" thoughtfully wrote:

Either will work. You will find that " there is more than one way to skin

a
cat"


ok fair enough.

With the worksheet loop, what are you trying to accomplish or is this a
homework assignment?


lol no not a homework assignment. I'm trying to teach myself excel
programming whilst trying to create a spreadsheet to personally use.

First of all many thanks for your help.

Basically what I want to do is, with the click of a button (no problem
creating the button and assigning a function), write a function that will:

1. copy columns A, B and C from row 7 onward to the last populated row

from
the 1st worksheet
2. past these cells into all remaining worksheets (12 - one for each

month)
into the same area, i.e., columns A, B and C from row 7 onward.

So in effect the function will access worksheet 1, copy the data, then

cycle
through the next 12 worksheets and paste the data in the same range as it
was collected from worksheet 1. I just can't figure out how to then cycle
through each row inside the cycle of each worksheet.

i.e. here's some pseudo code

for each ws in worksheets
'if this worksheet the first one
'copy data (cycle through each populated row starting from
row 7 copying columns A, B and C)
'else must be one of the remaining 12 worksheets so
'paste data

next ws




--