#1   Report Post  
Dave K
 
Posts: n/a
Default macro sheet select

I am relatively new to writing macros in VB, so I think the answer to this is
probably real simple. I need to set up a macro that deletes last month's
information from a specific worksheet, run an Advanced Filter (in a different
worksheet) based on information in the first sheet, copy the results, and
then paste them back in the first worksheet. The only problem I have is that
I need the sheet selection (in this case, Sheet1) to be a variable because I
will be running the same macro from multiple sheets. Here is my code:

Selection.AutoFilter Field:=1
Sheets("New Loans").Select
Columns("AD:BE").Select
Selection.delete Shift:=xlToLeft
ActiveWindow.LargeScroll ToRight:=-2
Range("newloans").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Sheets("Sheet1").Range("AD30:AD31"), CopyToRange:=Range("BG2"),
Unique:= _
False
ActiveWindow.SmallScroll ToRight:=6
Range("AE3:AK24").Select
Selection.Copy
ActiveWindow.LargeScroll ToRight:=-1
Sheets("Sheet1").Select
Range("A32").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A32").Select
Application.Run "Master2005.xls!hide"
Application.Run "Master2005.xls!formatting"
End Sub

Is there a way I can reference a cell value in the place of Sheet1? Hope
that all made sense. Thanks for your help.
  #2   Report Post  
bpeltzer
 
Posts: n/a
Default macro sheet select

You could create a variable to read the appropriate name from a known
location, then activate the sheet using the variable.
Dim MonthlySheet as String
....
worksheets("Settings").activate
MonthlySheet = range("A1").value
....
worksheets(MonthlySheet).activate
....
HTH. --Bruce

"Dave K" wrote:

I am relatively new to writing macros in VB, so I think the answer to this is
probably real simple. I need to set up a macro that deletes last month's
information from a specific worksheet, run an Advanced Filter (in a different
worksheet) based on information in the first sheet, copy the results, and
then paste them back in the first worksheet. The only problem I have is that
I need the sheet selection (in this case, Sheet1) to be a variable because I
will be running the same macro from multiple sheets. Here is my code:

Selection.AutoFilter Field:=1
Sheets("New Loans").Select
Columns("AD:BE").Select
Selection.delete Shift:=xlToLeft
ActiveWindow.LargeScroll ToRight:=-2
Range("newloans").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Sheets("Sheet1").Range("AD30:AD31"), CopyToRange:=Range("BG2"),
Unique:= _
False
ActiveWindow.SmallScroll ToRight:=6
Range("AE3:AK24").Select
Selection.Copy
ActiveWindow.LargeScroll ToRight:=-1
Sheets("Sheet1").Select
Range("A32").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A32").Select
Application.Run "Master2005.xls!hide"
Application.Run "Master2005.xls!formatting"
End Sub

Is there a way I can reference a cell value in the place of Sheet1? Hope
that all made sense. Thanks for your help.

  #3   Report Post  
Dave K
 
Posts: n/a
Default macro sheet select

Thanks for your help Bruce. I actually figured it out just before I saw your
post. Here is what worked for me...

Dim dataSheet As Worksheet
Set dataSheet = ActiveSheet

Thanks again.

"bpeltzer" wrote:

You could create a variable to read the appropriate name from a known
location, then activate the sheet using the variable.
Dim MonthlySheet as String
...
worksheets("Settings").activate
MonthlySheet = range("A1").value
...
worksheets(MonthlySheet).activate
...
HTH. --Bruce

"Dave K" wrote:

I am relatively new to writing macros in VB, so I think the answer to this is
probably real simple. I need to set up a macro that deletes last month's
information from a specific worksheet, run an Advanced Filter (in a different
worksheet) based on information in the first sheet, copy the results, and
then paste them back in the first worksheet. The only problem I have is that
I need the sheet selection (in this case, Sheet1) to be a variable because I
will be running the same macro from multiple sheets. Here is my code:

Selection.AutoFilter Field:=1
Sheets("New Loans").Select
Columns("AD:BE").Select
Selection.delete Shift:=xlToLeft
ActiveWindow.LargeScroll ToRight:=-2
Range("newloans").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Sheets("Sheet1").Range("AD30:AD31"), CopyToRange:=Range("BG2"),
Unique:= _
False
ActiveWindow.SmallScroll ToRight:=6
Range("AE3:AK24").Select
Selection.Copy
ActiveWindow.LargeScroll ToRight:=-1
Sheets("Sheet1").Select
Range("A32").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A32").Select
Application.Run "Master2005.xls!hide"
Application.Run "Master2005.xls!formatting"
End Sub

Is there a way I can reference a cell value in the place of Sheet1? Hope
that all made sense. Thanks for your help.

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
Data Range Mess Karen Charts and Charting in Excel 18 January 14th 06 02:34 PM
macro for Protecting a Sheet cincode5 Excel Discussion (Misc queries) 5 July 20th 05 11:59 AM
Dynamic Formulas with Dynamic Ranges Ralph Howarth Excel Worksheet Functions 5 January 21st 05 08:44 AM
Macro, select Sheet "Number", NOT Sheet Name DAA Excel Worksheet Functions 4 November 30th 04 05:29 PM
Naming & renaming a sheet tab Cgbilliar Excel Worksheet Functions 1 November 7th 04 05:57 PM


All times are GMT +1. The time now is 09:42 AM.

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"