ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   syntax issue (https://www.excelbanter.com/excel-programming/360708-syntax-issue.html)

JT

syntax issue
 
I would like to insert the following formula on the first sheet in the my
workbook to add up the same cell on each sheet in the workbook.

var1 = worksheets (1).name ' First
w = worksheets.count
var2 = worksheets(w).name ' Last

ActiveCell.FormulaR1C1 = "=SUM(First:Last!RC)"

I got this formula by recording a macro in Excel to get started. "First"
and "Last" are the sheet names for this workbook.

I would like to use 2 variables for the first and last worksheets (instead
of hard coding the sheet names since the names will be different depending on
the user.

I tried to put the above formula in a macro (with variables for the sheet
name) but when I look at the activecell, the formula is displayed instead of
the result.

Any help would be greatly appreciated. Thanks for your help..........
--
JT

Tom Ogilvy

syntax issue
 
var1 = worksheets (1).name ' First
w = worksheets.count
var2 = worksheets(w).name ' Last

ActiveCell.FormulaR1C1 = "=SUM(" & var1 & ":" & var2 & "!RC)"

--
Regards,
Tom Ogilvy


"JT" wrote:

I would like to insert the following formula on the first sheet in the my
workbook to add up the same cell on each sheet in the workbook.

var1 = worksheets (1).name ' First
w = worksheets.count
var2 = worksheets(w).name ' Last

ActiveCell.FormulaR1C1 = "=SUM(First:Last!RC)"

I got this formula by recording a macro in Excel to get started. "First"
and "Last" are the sheet names for this workbook.

I would like to use 2 variables for the first and last worksheets (instead
of hard coding the sheet names since the names will be different depending on
the user.

I tried to put the above formula in a macro (with variables for the sheet
name) but when I look at the activecell, the formula is displayed instead of
the result.

Any help would be greatly appreciated. Thanks for your help..........
--
JT



All times are GMT +1. The time now is 08:58 PM.

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