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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,147
Messages
6,123,296
Members
449,095
Latest member
Chestertim

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