How can a variable for sheet be used to reference a cell

Ken F

New Member
Joined
Mar 19, 2003
Messages
2
This is a spinoff of the original thread: "Macro to add numbers from different worksheets (Excel 2000)"

I got GREAT answers how to use a 3d formula in contiguous sheets, but I can't guarantee I know the names of the first and last sheets and I can't guarantee they will be contiguous.

So I am trying to write a macro to total all sheets except those with a certain name as shown below. When I try to access cell B7 on sheet s, I get a compile error on two lines that says "Object Required". What am I doing wrong? Here is the macro:

a = 0
b = 0
For Each s In Worksheets
If s.Name <> "Directories" Then
If s.Name <> "Summary" Then
b = b + s.Name!B7 <-----------PROBLEM HERE
a = a + (s.Name!B7 / s.Name!B10) <--------AND HERE
End If
End If
Next s
Range("B7").Select
ActiveCell.FormulaR1C1 = b
Range("B10").Select
ActiveCell.FormulaR1C1 = a

THANKS!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,936
Latest member
almerpogi

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