Sheet name and copy paste macro

mfd2112

Board Regular
Joined
Jan 2, 2010
Messages
86
Hi,
I have a couple questions about these macros.
The locations macro copies from a sheet named Wkd and I can’t figure out how to have the macro run without having to be at that sheet.
The location macro will paste the filtered data in a new sheet that was created from a template “Blank” sheet, how can the macro delete the all the rows below what was pasted in the new sheet.
Also I’m trying to combine this code with code that creates sheets and names the sheets from a sheet with a list “List”. Currently I run the createSheetNames first then I run the Loactions macro but if they can be combined that would be awesome.
Code:
[FONT=Verdana][COLOR=black]Sub CreateNameSheets()[/COLOR][/FONT]
[FONT=Verdana][COLOR=black] ' by Dave Peterson[/COLOR][/FONT]
[FONT=Verdana][COLOR=black] ' List sheetnames required in col B in a sheet: List[/COLOR][/FONT]
[FONT=Verdana][COLOR=black] ' Sub will copy sheets based on the sheet named as: Template[/COLOR][/FONT]
[FONT=Verdana][COLOR=black] ' and name the sheets accordingly[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Dim TemplateWks As Worksheet[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Dim ListWks As Worksheet[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Dim ListRng As Range[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Dim mycell As Range[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Set TemplateWks = Worksheets("Blank")[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Set ListWks = Worksheets("List")[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      With ListWks[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      Set ListRng = .Range("B1", .Cells(.Rows.Count, "B").End(xlUp))[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  End With[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  For Each mycell In ListRng.Cells[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      TemplateWks.Copy after:=Worksheets(Worksheets.Count)[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      On Error Resume Next[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      ActiveSheet.Name = mycell.Value[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      If Err.Number <> 0 Then[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]          MsgBox "Please fix: " & ActiveSheet.Name[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]          Err.Clear[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      End If[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]      On Error GoTo 0[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Next mycell[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]End Sub[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]Sub Locations1()[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Dim Lastrow As Long     'Last used row in column A[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Lastrow = Range("A" & Rows.Count).End(xlUp).Row[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]  Range("A2:A" & Lastrow).AutoFilter Field:=1, Criteria1:="=10th & 102nd"[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("A3:L" & Lastrow).Cells.Copy[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]  Sheets("10th & 102nd").Select[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("A3").PasteSpecial[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("H3").Select[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]  Sheets("Wkd").Select[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("A2:A" & Lastrow).AutoFilter Field:=1, Criteria1:="=145th & I-5"[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("A3:L" & Lastrow).Cells.Copy[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]  Sheets("145th & I-5").Select[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("A3").PasteSpecial[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("H3").Select[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]  Sheets("Wkd").Select[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("H3").Select[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Application.CutCopyMode = False[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  ActiveSheet.AutoFilterMode = False[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("A2:L2").Select[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Selection.AutoFilter[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]  Range("H3").Select[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]End Sub[/COLOR][/FONT]
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Ok, Jerry did it 'SHEET1 TO MANY SHEETS<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Thanks Jerry those are awesome! Works excellent!<o:p></o:p>
My regards,<o:p></o:p>
Dale<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top