Processing code on wrong sheet

J

Jeff Klein

I Have a workbook with many sheets. I have code that calculates fields on
all of the sheets and writes the calculations on a "Summary" sheet. My
problem is: the calculations are showing up on the last sheet edited (not
the summary sheet) Any help is appreciated.

Below is the code:

Private Sub Workbook_Open()
Dim sh As Worksheet, sh1 As Worksheet
Dim i As Long

Set sh = Worksheets("Summary")
i = 0
For Each sh1 In Worksheets
If sh.Name <> sh1.Name Then
i = i + 1
Cells(i, 1).Value = sh1.Range("c36").Value
Cells(i, 2).Value = sh1.Range("M34").Value
End If
Next
End Sub
 
R

Ron de Bruin

Hi Jeff
Cells(i, 1).Value = sh1.Range("c36").Value
Cells(i, 2).Value = sh1.Range("M34").Value

This use the activesheet

use this

sh.Cells(i, 1).Value = sh1.Range("c36").Value
 

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