Need to apply VBA code to multiple Worksheets

P

parteegolfer

I have this code listed below which is in a macro module. Is there a way
that I can apply this code to only the worksheet I am working in. I have
worksheets labeled January thru December and need to distinqiush between
the sheets.

Dim rng As Range
Dim lastrow As Long, r As Long, i As Integer
With Worksheets("January") <<----This needs to be a variable for each
sheet
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
r = 1
srow = r
Do
Do
r = r + 1
Loop Until .Cells(r, "a") = "Weekly Subtotal" Or r >= lastrow
For i = 4 To 6
Set rng = .Range(.Cells(srow, i), .Cells(r - 1, i))
Cells(r, i) = Application.Sum(rng)
Next i
srow = r + 1
Loop Until srow > lastrow
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top