davidandrewlawrence
New Member
- Joined
- Feb 19, 2008
- Messages
- 3
Hello,
My first post, please be nice
My coding skills aren't great, but otherwise very well skilled in Excel.
Hoping somebody can help, I'm stumped.
I have a workbook with tables and charts that are populated from another worksheet (in the same workbook) using lookups.
There is a dropdown box which list some geographical areas and upon selecting a new area the worksheet re-populates.
Standard stuff.
My issue is I want to be able to loop through each area , each time copying the contents of the worksheet, open a blank template, paste the data, save it as the area's name, close the document (it needs to be emailed as attachment).
Repeat until the end of the list.
I've made a start, but I'm getting a runtime error 9 message and I can't see that the issue is. I know the code works to a point, but can't check after. The blank workbook will open but then it falls over.
Grateful for any help, be it tweaks or have my code ripped apart and done differently! Cheers.
My code reads:
Sub LoopClusterAndSave()
'set range
Dim rng As Range
'this is where my dropdown list populates from
Set rng = Sheets("Cluster list").Range("A1:A24")
'Select the first cluster in the drop down list:
For Each cell In rng.Cells
Sheets("PickACluster").Range("A1").Value = cell.Value 'PickACluster is the name of the worksheet with my data
'Select the entire worksheet to copy
Sheets("PickACluster").Select
Cells.Select
'Copy it
Selection.Copy
'Open the blank template document where we want to paste this data:
Workbooks.Open Filename:="\\netapp04-cifs\lcc017\ELSSI\SEMH CLUSTER DATA\City Wide Cluster Reporting and Recording\Central Collation & Analysis Tools\BlankChartTemplate.xlsx"
'Activate this window
Windows("BlankChartTemplate.xlsx").Activate
'Select the top left cell where I will paste all data
ActiveWorkbook.Sheets(1).Range("A1").Select
'Paste the clipboard
ActiveWorkbook.Sheets(1).Paste
Next cell
End Sub
My first post, please be nice
My coding skills aren't great, but otherwise very well skilled in Excel.
Hoping somebody can help, I'm stumped.
I have a workbook with tables and charts that are populated from another worksheet (in the same workbook) using lookups.
There is a dropdown box which list some geographical areas and upon selecting a new area the worksheet re-populates.
Standard stuff.
My issue is I want to be able to loop through each area , each time copying the contents of the worksheet, open a blank template, paste the data, save it as the area's name, close the document (it needs to be emailed as attachment).
Repeat until the end of the list.
I've made a start, but I'm getting a runtime error 9 message and I can't see that the issue is. I know the code works to a point, but can't check after. The blank workbook will open but then it falls over.
Grateful for any help, be it tweaks or have my code ripped apart and done differently! Cheers.
My code reads:
Sub LoopClusterAndSave()
'set range
Dim rng As Range
'this is where my dropdown list populates from
Set rng = Sheets("Cluster list").Range("A1:A24")
'Select the first cluster in the drop down list:
For Each cell In rng.Cells
Sheets("PickACluster").Range("A1").Value = cell.Value 'PickACluster is the name of the worksheet with my data
'Select the entire worksheet to copy
Sheets("PickACluster").Select
Cells.Select
'Copy it
Selection.Copy
'Open the blank template document where we want to paste this data:
Workbooks.Open Filename:="\\netapp04-cifs\lcc017\ELSSI\SEMH CLUSTER DATA\City Wide Cluster Reporting and Recording\Central Collation & Analysis Tools\BlankChartTemplate.xlsx"
'Activate this window
Windows("BlankChartTemplate.xlsx").Activate
'Select the top left cell where I will paste all data
ActiveWorkbook.Sheets(1).Range("A1").Select
'Paste the clipboard
ActiveWorkbook.Sheets(1).Paste
Next cell
End Sub