Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Pivot Tables Formatting interior color &Type Mismatch

I have created a function to color the interior of cells that contain
percentages (field is "pcnt variance" with 7 different colors from cold
(blue) to hot (red) for my sales application. I'm sure the code could be
better/more efficient but it works ok on defined ranges, however I get a type
mismatch error when I try to apply it to a Pivot table, sometimes, but not
always. It usually blows up when I drag another field down to the rows area.
Is the problem the range? Any help would be appreciated. Below is the code.

Sub colorcells2()

Dim rngsales As Range
Dim i As Integer
Dim j As Integer

Set rngsales = Range("mytable")
For i = 0 To rngsales.Rows.Count - 1
For j = 0 To rngsales.Columns.Count - 1

If ActiveCell.Offset(i, j).Value < -0.04 And ActiveCell.Offset(i,
j).Value -10 Then
ActiveCell.Offset(i, j).Interior.ColorIndex = 31
ElseIf ActiveCell.Offset(i, j).Value < -0.02 And
ActiveCell.Offset(i, j).Value = -0.04 Then
ActiveCell.Offset(i, j).Interior.ColorIndex = 37
ElseIf ActiveCell.Offset(i, j).Value < -0# And
ActiveCell.Offset(i, j).Value = -0.02 Then
ActiveCell.Offset(i, j).Interior.ColorIndex = 35
ElseIf ActiveCell.Offset(i, j).Value 0# And
ActiveCell.Offset(i, j).Value < 0.02 Then
ActiveCell.Offset(i, j).Interior.ColorIndex = xlNone
ElseIf ActiveCell.Offset(i, j).Value = 0.02 And
ActiveCell.Offset(i, j).Value < 0.04 Then
ActiveCell.Offset(i, j).Interior.ColorIndex = 27
ElseIf ActiveCell.Offset(i, j).Value = 0.04 And
ActiveCell.Offset(i, j).Value < 0.08 Then
ActiveCell.Offset(i, j).Interior.ColorIndex = 45
ElseIf ActiveCell.Offset(i, j).Value = 0.08 And
ActiveCell.Offset(i, j).Value < 10 Then
ActiveCell.Offset(i, j).Interior.ColorIndex = 3
Else
ActiveCell.Offset(i, j).Interior.ColorIndex = xlNone
End If
Next
Next

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
pivot tables for likert-scale type survey items kk Excel Worksheet Functions 2 July 12th 07 02:58 PM
When refreshing pivot tables my pivot table chart type changes hannah220507 Excel Discussion (Misc queries) 1 May 22nd 07 02:57 PM
Help!! Instead of Conditional Formatting, pull interior color from lookup bhumvee Excel Programming 0 June 1st 04 05:21 PM
Conditional formatting & interior color Paul S Panoff Excel Programming 2 April 22nd 04 09:38 PM
Type Mismatch Phil Hageman[_3_] Excel Programming 2 January 9th 04 06:11 PM


All times are GMT +1. The time now is 01:32 PM.

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"