ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   2 VB Questions (https://www.excelbanter.com/excel-worksheet-functions/205315-2-vbulletin-questions.html)

JRD-CFW[_2_]

2 VB Questions
 
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

TomPl

2 VB Questions
 
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

TomPl

2 VB Questions
 
I forgot it was a different sheet. Try this:

Sub testit()

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

End Sub



All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com