![]() |
Need Macro to run on all Worksheets at same time
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 |
Need Macro to run on all Worksheets at same time
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. |
Need Macro to run on all Worksheets at same time
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 |
All times are GMT +1. The time now is 04:45 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com