Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel 2003 Pivot and VBA loop through each record to change cellbackground color based on conditions

I am using a pivot table to track grape intake for a winery. Since
Excel 2003 is limited to 3 conditions in the conditional formatting
feature, I am trying to write VBA code to:

================================================== ==
PSEUDO CODE
Do After Table Update
Select Range of Varname
Start Loop Through all Records
If PivotItem is cell with data
Find Varname of first record
Find Sugar of first record
If Sugar 0
Case Varname = MERLOT and Sugar < 24
Change background of Varname cell to yellow
Case Varname = SYRAH and Sugar < 24
Change background of Varname cell to yellow
Case Varname = FRENCH COLOMBARD and Sugar < 23
Change background of Varname cell to yellow
Case Varname = CABERNET SAUVIGNON and Sugar < 24
Change background of Varname cell to yellow
Case Varname = CHENIN BLANC and Sugar < 20.5
Change background of Varname cell to yellow
Case Varname = CARIGNANE and Sugar < 24
Change background of Varname cell to yellow
End Case
End If
End If
Loop to next record and continue to do for all records
================================================== ==

Could the case evaluation also say something like:

Case (Varname = MERLOT or Varname = SYRAH or Varname = CABERNET
SAUVIGNON_
or Varname = CARIGNANE) and Sugar < 24

================================================== ==

Here is the code I have been toying with. It gets a '1004' error. I
seem to struggle with selecting the right cell and comparing the cell
contents in the program code.

Sub FormatPivotCells()
Dim ws As Worksheet, pt As PivotTable, pf As PivotField, i As Long, j
As Long
Dim vn As String, bx As Double

Set ws = ActiveSheet

If ws.PivotTables.Count < 1 Then
MsgBox "No PivotTables on ActiveSheet. Exiting routine.",
vbInformation
Exit Sub
End If

Set pt = ws.PivotTables(1)

ws.PivotTables(1).PivotFields("Varname").DataRange .Select

For i = 1 To pt.PivotFields("Varname").DataRange.Count
vn = ws.PivotTables(1).PivotFields("Varname").PivotItem s(i)
bx = ws.PivotTables(1).PivotFields("Sugar").PivotItems( i)

Next i

'pt.PivotCache.Refresh


End Sub
================================================== ==========
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting based on two conditions in excel 2003 Anand Excel Worksheet Functions 4 March 25th 10 11:42 AM
Need help to change a cell color based on conditions Ken Excel Worksheet Functions 1 January 28th 10 09:29 AM
How to set color for text based on conditions? Eric Excel Discussion (Misc queries) 2 October 12th 08 05:34 PM
Loop to change cell color based on found value? gaba Excel Programming 3 November 3rd 04 02:33 PM
color formatting based on 12 conditions scire[_2_] Excel Programming 1 May 15th 04 10:50 AM


All times are GMT +1. The time now is 12:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"