Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have a workbook where data is compiled through out the year and has to be re-ran from the beginning of the year each month due to changes in open orders. I also have worksheets breaking down each month, but it has become a problem recreating the worksheets each month. I have code (from Ron de Bruin) to create a worksheet for each month ("01-09", "02-09", etc.). Now, I want to save the workbook (ActiveWorkbook.Save) after the pages are created and run the following code for worksheets named 01-09, 02-09, etc. This will work for one worksheet, but I can't seem to find the right code to make it work for an array of worksheets. It will sort and subtotal specified columns and then bold total rows and insert a row after each total row. Sub Total_Worksheets() Dim rng As Range Range("A1:p900").Select Selection.Sort Key1:=Range("c2"), Order1:=xlAscending, _ Key2:=Range("A2"), Order2:=xlAscending, _ Key2:=Range("b2"), Order2:=xlAscending, _ Header:=xlYes With Sheets("02-09") On Error Resume Next Set rng = Range(Range("j2"), Cells(2, Columns.Count).End(xlToLeft)) On Error GoTo 0 If Not rng Is Nothing Then .Range("j2").Subtotal _ GroupBy:=3, _ Function:=xlSum, _ TotalList:=Array(10, 11, 12), _ Replace:=False, _ PageBreaks:=False, _ SummaryBelowData:=True .Range("j2").Subtotal _ GroupBy:=1, _ Function:=xlSum, _ TotalList:=Array(10, 11, 12), _ Replace:=False, _ PageBreaks:=False, _ SummaryBelowData:=True .Range("j2").Subtotal _ GroupBy:=2, _ Function:=xlSum, _ TotalList:=Array(10, 11, 12), _ Replace:=False, _ PageBreaks:=False, _ SummaryBelowData:=True End If End With Dim LastRow As Long Dim r As Long LastRow = Range("G" & Rows.Count).End(xlUp).Row For r = LastRow To 2 Step -1 If InStr(1, Cells(r, 1).Value, "Total") 0 Or _ InStr(1, Cells(r, 2).Value, "Total") 0 Or _ InStr(1, Cells(r, 3).Value, "Total") 0 Or _ InStr(1, Cells(r, 4).Value, "Total") 0 Then Range(Cells(r, 1), Cells(r, 30)).Font.Bold = True ActiveSheet.Rows(r + 1).EntireRow.Insert End If Next End Sub If this is possible to do over multiple sheets, I would really appreciate code to make it work. Thanks in advance, Phisaw |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copying a range of data across multiple worksheets | Excel Programming | |||
Copying a range of data across multiple worksheets | Excel Programming | |||
Sum same cell/range of multiple worksheets within a workbook... | Excel Worksheet Functions | |||
same named range on multiple worksheets? | Excel Discussion (Misc queries) | |||
range problem with multiple use of subtotal function | Excel Programming |