Hi All
Been a while since I've coded excel and never got my head around loops so I'm hoping someone will offer some assistance.
I have a workbook that has imported data on Sheet1 and Sheet2 (sheet Index not name)
Sheet 1 has 132 Col with named ranges "$A$3:$A$1442" is "TimeStamp" then all other Col "$x$3:$x$1442" (where x is Col 2 through 131) and named Meter1 through Meter131
Sheet 2 has a range of names in "A1:A132"
I have working code to add new sheets based on the range on sheet2 (although for testing purposes I am limiting this to 5 new sheets
I also have working code to copy the "Timestamp" range to all sheets except the first 2
I have the following code to copy a named range to a sheet at "B1
What I'm looking to do is loop through this code for each of the sheets from sheet 3 to the last sheet increasing the named range number by 1 so in essence it would be carrying out the following
I'm assuming it would look (roughly) something along the line of......
Any assistance is greatly appreciated
Been a while since I've coded excel and never got my head around loops so I'm hoping someone will offer some assistance.
I have a workbook that has imported data on Sheet1 and Sheet2 (sheet Index not name)
Sheet 1 has 132 Col with named ranges "$A$3:$A$1442" is "TimeStamp" then all other Col "$x$3:$x$1442" (where x is Col 2 through 131) and named Meter1 through Meter131
Sheet 2 has a range of names in "A1:A132"
I have working code to add new sheets based on the range on sheet2 (although for testing purposes I am limiting this to 5 new sheets
I also have working code to copy the "Timestamp" range to all sheets except the first 2
I have the following code to copy a named range to a sheet at "B1
VBA Code:
Range("Meter1").Copy (Worksheets(3).Range("B1"))
What I'm looking to do is loop through this code for each of the sheets from sheet 3 to the last sheet increasing the named range number by 1 so in essence it would be carrying out the following
VBA Code:
Range("Meter1").Copy (Worksheets(3).Range("B1"))
Range("Meter2").Copy (Worksheets(4).Range("B1"))
Range("Meter3").Copy (Worksheets(3).Range("B1"))
'etc, etc.....
I'm assuming it would look (roughly) something along the line of......
VBA Code:
Sub CopyPaste()
Dim m As Double, w As Double, ws As Worksheet
'I'm assuming I've declared the variable to store the number of sheets but don't know if that correct
For Each ws In Worksheets
'this is the bit I need help with
'to set the variable m on each loop starting at 1 and add to Meter so the Range changes to Meter1, Meter2.....Meter131
'to set the variable w on each loop starting at 3 and insert into the Worksheets index () so the index increase Worksheet(3), Worksheet(4)......Worksheet(133)
Range("Meter" & m).Copy (Worksheets(w).Range("B1"))
'not sure if this is even close to the correct syntax
Next ws
End Sub
Any assistance is greatly appreciated