ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   calculatedfields (https://www.excelbanter.com/excel-programming/332746-calculatedfields.html)

Geoff

calculatedfields
 
Hi,
I have 2 table titles in a spreadsheet, 'Rest & Breaks" and 'Driving
Time'. When creating a PivotTable I get :
..PivotFields("Rest & Breaks") and
..PivotFields("Driving Time")

These are ok but how do i create a calculated field adding the 2 values
together? The following line does not work:

..CalculatedFields.Add "Duty Time", "=Rest & Breaks + Driving Time", True

I believe it is the '&' in Rest & Breaks which is the problem.

How can I get round this please without altering the titles.

T.I.A.

Geoff



GB

calculatedfields
 
Bracket the fields that you are adding with a single quote '
Such as " = 'Rest & Breaks' + 'Driving Time' "
(I have added and removed some spaces to make it easier to see, not sure how
well the "program" will handle the "additional" quotes or if it will
understand that Driving Time is different than Driving Time

But should fix your problem.


"Geoff" wrote:

Hi,
I have 2 table titles in a spreadsheet, 'Rest & Breaks" and 'Driving
Time'. When creating a PivotTable I get :
.PivotFields("Rest & Breaks") and
.PivotFields("Driving Time")

These are ok but how do i create a calculated field adding the 2 values
together? The following line does not work:

.CalculatedFields.Add "Duty Time", "=Rest & Breaks + Driving Time", True

I believe it is the '&' in Rest & Breaks which is the problem.

How can I get round this please without altering the titles.

T.I.A.

Geoff



Geoff

calculatedfields
 
Hi GB
That worked fine :):)
I had tried parsing the PTable string with all sorts of combinations of
double quotes, never thought of single ones.
The spaces in the original code were accepted ok in fact if the string is in
any way different from the table header it will give an error.

Many thanks for the help.

Geoff

"GB" wrote:

Bracket the fields that you are adding with a single quote '
Such as " = 'Rest & Breaks' + 'Driving Time' "
(I have added and removed some spaces to make it easier to see, not sure how
well the "program" will handle the "additional" quotes or if it will
understand that Driving Time is different than Driving Time

But should fix your problem.


"Geoff" wrote:

Hi,
I have 2 table titles in a spreadsheet, 'Rest & Breaks" and 'Driving
Time'. When creating a PivotTable I get :
.PivotFields("Rest & Breaks") and
.PivotFields("Driving Time")

These are ok but how do i create a calculated field adding the 2 values
together? The following line does not work:

.CalculatedFields.Add "Duty Time", "=Rest & Breaks + Driving Time", True

I believe it is the '&' in Rest & Breaks which is the problem.

How can I get round this please without altering the titles.

T.I.A.

Geoff




All times are GMT +1. The time now is 09:38 AM.

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