View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Angie Angie is offline
external usenet poster
 
Posts: 79
Default macro in excel 2007

This is the code. Under the Activeworkbook.worksheets"smith", smith is the
name of the worksheet.

Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+a
'
Range(Selection, Selection.End(xlToRight)).Select
ActiveCell.Range("A1:AD1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:AD30").Select
ActiveWorkbook.Worksheets("smith").Sort.SortFields .Clear
ActiveWorkbook.Worksheets("smith").Sort.SortFields .Add Key:=ActiveCell. _
Offset(0, 24).Range("A1:A24"), SortOn:=xlSortOnValues,
Order:=xlDescending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("smith").Sort.SortFields .Add Key:=ActiveCell. _
Offset(0, 3).Range("A1:A24"), SortOn:=xlSortOnValues,
Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("smith").Sort.SortFields .Add Key:=ActiveCell. _
Offset(0, 6).Range("A1:A24"), SortOn:=xlSortOnValues,
Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("smith").Sort
.SetRange ActiveCell.Offset(-1, 0).Range("A1:AD25")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.Subtotal GroupBy:=25, Function:=xlSum, TotalList:=Array(11,
12, _
13, 14, 15, 16, 17, 18, 19, 20, 21, 24), Replace:=True,
PageBreaks:=False, _
SummaryBelowData:=True
Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(11, 12,
13 _
, 14, 15, 16, 17, 18, 19, 20, 21, 24), Replace:=False,
PageBreaks:=False, _
SummaryBelowData:=True

End Sub




"Barb Reinhardt" wrote:

Please post your code. I suspect it's a fairly easy fix if we see what you
have.

"Angie" wrote:

I have a workbook with mutliple worksheets, I create a macro to sort and
subtotal data in a worksheet, but when I apply the macro to another
worksheet, it does not work. When I look at the program, it looks like the
macro is worksheet specific. Can someone help?