programerAnel

New Member
Joined
Aug 28, 2018
Messages
5
To create pivot table i use

Code:
xlBook.ActiveSheet.PivotTableWizard(Excel.XlPivotTableSourceType.xlDatabase, xlSheet.Range("A1:D" & ukupno))
xlBook.ActiveSheet.PivotTables(1).PivotFields("Poslovna jedinica").Orientation = Excel.XlPivotFieldOrientation.xlRowField
xlBook.ActiveSheet.PivotTables(1).PivotFields("Opština").Orientation = Excel.XlPivotFieldOrientation.xlColumnField

xlBook.ActiveSheet.PivotTables(1).PivotFields("Neto").Orientation = Excel.XlPivotFieldOrientation.xlDataField
xlBook.ActiveSheet.PivotTables(1).PivotFields("Number of workers").Orientation = Excel.XlPivotFieldOrientation.xlDataField

After that i need to format the column "Neto" to
Code:
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"

The point is if i use like this

Code:
xlBook.Worksheets("Pivot").Range("C:F").NumberFormat = "#,##0.00_);[Red](#,##0.00)"

it will format the column "Number of workers" as well which i don't want to

How to format only column "Neto" or as many exist, because it can be from 1 to n
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I managed to work it out.

Code:
xlBook.Worksheets("Pivot").PivotTables(1).PivotSelect("Sum of Neto", Excel.XlPTSelectionMode.xlDataOnly)
Dim MySelection As Excel.Range = xlApp.Selection
MySelection.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
MySelection.HorizontalAlignment = Excel.Constants.xlRight
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,773
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top