Macro

Marika

New Member
Joined
Jul 1, 2004
Messages
38
I have a macro that's running on 1 worksheet, but would like to include certain other worksheets as well (Other worksheets has same data only diff. values)
TIA
 
Marika,

You need to qualify the range with the active sheet:

Private Sub CommandButton1_Click()
Dim lngRow As Long
Dim Sharr(), Sh

Sharr = Array(Sheets("Sunday Night"), Sheets("Monday Morning"), Sheets("Tuesday Morning"))

For Each Sh In Sharr

lngRow = WorksheetFunction.Max(Sh.Range("a65536").End(xlUp).Row, Sh.Range("b65536").End(xlUp).Row)

Sh.Range("A" & lngRow + 2) = "Monday Total"
Sh.Range("B" & lngRow + 2).Formula = "=SumProduct(--(Weekday(L2:L" & lngRow & ") = 2))"
Sh.Range("A" & lngRow + 3) = "Tuesday Total"
Sh.Range("B" & lngRow + 3).Formula = "=SumProduct(--(Weekday(L2:L" & lngRow & ") = 3))"
Sh.Range("A" & lngRow + 4) = "Wednesday Total"
Sh.Range("B" & lngRow + 4).Formula = "=SumProduct(--(Weekday(L2:L" & lngRow & ") = 4))"
Sh.Range("A" & lngRow + 5) = "Thursday Total"
Sh.Range("B" & lngRow + 5).Formula = "=SumProduct(--(Weekday(L2:L" & lngRow & ") = 5))"
Sh.Range("A" & lngRow + 6) = "Friday Total"
Sh.Range("B" & lngRow + 6).Formula = "=SumProduct(--(Weekday(L2:L" & lngRow & ") = 6))"
Sh.Range("A" & lngRow + 7) = "Saturday Total"
Sh.Range("B" & lngRow + 7).Formula = "=SumProduct(--(Weekday(L2:L" & lngRow & ") = 7))"
Sh.Range("A" & lngRow + 8) = "Sunday Total"
Sh.Range("B" & lngRow + 8).Formula = "=SumProduct(--(Weekday(L2:L" & lngRow & ") = 1))"
Sh.Range("A" & lngRow + 9) = "Grand Total"
Sh.Range("B" & lngRow + 9).Formula = "=Sum(B" & lngRow + 2 & ":B" & lngRow + 8 & ")"
Sh.Range("A" & lngRow + 10) = "Duration Count"
Sh.Range("B" & lngRow + 10).Formula = "=Sum(J1:J" & lngRow & ")"
Sh.Range("B" & lngRow + 2, "L" & lngRow + 10).NumberFormat = "0"

Next Sh

End Sub


Regards,

Mike
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
on the compile error that i am encountering: could it be a version problem. i am using excel 97 with NT OS.

Stromma, what are you using? Hotpepper?
 
Upvote 0
I'm using xl 2000 - Win2k, xp.

I don't think that NT would be a part of the problem.

Without having any experince of xl97, i know that there are quit big difference's between are versions. I guess that it could be related xl97, but i honestly can't say if that's really the problem.

Anyone else who knows?

/Roger
 
Upvote 0

Forum statistics

Threads
1,215,963
Messages
6,127,964
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top