2 VB Questions

J

JRD-CFW

1) If I'm writing a worksheet_change for sheet1, how do i get it to reference
sheet2? That is, I want Sum(Sheet2!A2:A10)?

2) If I have A1=Sum(Range("A2:A10")) written into VB, how do I make it
update automatically when I change the value in, say, A3?

Thanks.

JRD-CFW
 
T

TomPl

If you put this formula:

=SUM(A2:A10)

in cell A1 it will automatically update any time there is a change to the
worksheet.


However, if you need to do it in code, try this:

Sub testit()

ActiveSheet.Range("A1").Value = WorksheetFunction _
..Sum(Range("A2:A10"))

End Sub


I hope that helps.

Tom
 
T

TomPl

I forgot it was a different sheet. Try this:

Sub testit()

ActiveSheet.Range("A1").Value = WorksheetFunction _
..Sum(Sheets("Sheet2").Range("A2:A10"))

End Sub
 

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

Similar Threads


Top