PC Review


Reply
Thread Tools Rate Thread

Active sheet problem / macro button

 
 
manfred3
Guest
Posts: n/a
 
      15th Apr 2010
Hi ,

I want to be able to run the code below from any sheet and also with a
macro button.
I want to place the macro button on the first sheet [financial
summary]. but the macro filter would be activated on a different sheet
[production_schedule}

Sub CopyFilter()
Application.ScreenUpdating = False

Dim rng As Range
Dim rng2 As Range


If Not ActiveSheet.AutoFilterMode Then
ActiveSheet.Range("F3").AutoFilter
End If
ActiveSheet.Range("$A$4:$IK$3277").AutoFilter Field:=6, Criteria1:= _
"HR & Payroll"
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("HR&PAYROLL").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("HR&PAYROLL").Range("A5")
End If
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode =
False

Rows("1:4").Select
Selection.Copy
Sheets("HR&PAYROLL").Select
Rows("1:1").Select
ActiveSheet.Paste
Cells.Select
Application.CutCopyMode = False
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With

Rows("2:2").Select
Selection.Copy
Sheets("HR&PAYROLL").Select
Rows("2:2").Select
ActiveSheet.Paste
Range("A2:J2").Select

With Selection.Font
.FontStyle = "Bold"
.Size = 10
End With
Application.CutCopyMode = False

With Selection
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False

End With

Sheets("HR&PAYROLL").Select
Cells.Select
Selection.Columns.AutoFit
Selection.Rows.AutoFit
Rows("2:2").Select
Selection.Font.Bold = True
Selection.Font.Underline = xlUnderlineStyleSingle

Application.ScreenUpdating = True

End Sub

Thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delette active sheet from form button TimSpangler Microsoft Excel Programming 5 9th Oct 2009 11:53 PM
save only active sheet Button. tim Microsoft Excel Misc 7 23rd May 2008 11:27 PM
ow can I get the active sheet name to a var in a macro?? =?Utf-8?B?aXRhbG8=?= Microsoft Excel Programming 1 16th May 2006 10:36 PM
Pause macro, add form button to sheet, continue macro when button clicked! Flystar Microsoft Excel Programming 1 26th May 2004 09:45 AM
How to end macro on inital active worksheet containing macro button that was clicked =?Utf-8?B?U2lsdmVyaGF3azE=?= Microsoft Excel Programming 2 14th May 2004 03:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:48 PM.