Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a macro below that runs perfectly, but I would like it to run
on all worksheets and not just the active worksheet. The format on each worksheet is identical, only the data differs. Could someone help me add the extra code needed for the code to run on all worksheets at the same time? Thanks. Sub SubTotal_All_Worksheets() Dim intI As Integer Dim intJ As Integer Dim intK As Integer Dim strA As String Dim strB As String Dim strFormula As String Dim CDelta As String Dim RStart As String Dim CSum As String CSum = InputBox("For which column do you wish to create sub- totals?", "Sub-Total") CDelta = InputBox("Create sums for each change in what column?", "Column") RStart = InputBox("What is the first row of data in that column?", "Row") intJ = 0 intK = 0 Range(CDelta & RStart).Select For intI = 1 To 20000 strA = Range(CDelta & intI + RStart - 1 + intJ) strB = Range(CDelta & intI + RStart + intJ) If strA = strB Then intK = intK + 1 Else: Range(CDelta & intI + 2 + intJ).Select Selection.EntireRow.Insert strFormula = "=sum(" & CSum & (intI + RStart - 1 + intJ) & ":" & CSum & (intI + RStart - 1 + intJ - intK) & ")" Range(CSum & intI + RStart + intJ) = strFormula Range(CSum & intI + RStart + intJ).Select Selection.Font.Bold = True intJ = intJ + 1 intK = 0 End If Next intI End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this:
Dim objWorksheet As Worksheet For Each objWorksheet In ActiveWorkbook.Worksheets 'Insert your code here and refer to objWorksheet 'i.e objWorksheet.Range(CSum & intI + RStart + intJ) = strFormula Next objWorksheet That'll loop through all the worksheets for you. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Mar 16, 11:27 am, wrote:
Try this: Dim objWorksheet As Worksheet For Each objWorksheet In ActiveWorkbook.Worksheets 'Insert your code here and refer to objWorksheet 'i.e objWorksheet.Range(CSum & intI + RStart + intJ) = strFormula Next objWorksheet That'll loop through all the worksheets for you. Could you give me a little more guidance? I can't seem to get it to work. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro / function text time to 24hr excel time passed midnight fortotaling hr's | Excel Worksheet Functions | |||
Scrolling all worksheets at the same time | Excel Discussion (Misc queries) | |||
VBA / Macro for creating new worksheets and new columns from existing worksheets | Excel Programming | |||
time and auto macro run by setting time | Excel Programming | |||
Help with Macro to Convert Date/Time to Time Only | Excel Programming |