Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Hide columns according to background fill color

I am having trouble understanding how Excel handles colors.

I have a public sub that sets a public variable, "TermColor" using the RGB function. TermColor is of type MsoRGBType.

In another module, I use the TermColor variable as follows:

Sub WeedColsByColor(ByRef Clr, ByRef WS)

Dim LastCol, i As Long

With Worksheets(WS)

LastCol = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count

'hide columns if they have one of the forbidden colors
Debug.Print (CBool(.Cells(2, i).Interior.Color = Clr))
For i = 1 To LastCol
If .Cells(2, i).Interior.Color = Clr Then
.Cells(2, 1).EntireColumn.Hidden = True
End If '.Cells(2, i).Interior.Color = Color Then
Next i
End With 'Worksheets(WS)
End Sub

The debug statement gives me an error: Run-time error '1004': Application-defined or object-defined error

When I take the debug statement out and call the sub, I get nothing - no error, but also no columns are hidden. Using another debug statement, I am able to see that the IF statement is never entered.

Does anyone know either of the following:
1. How to phrase the IF statement so it compares cell color to Clr, or
2. How to output the .color and Clr to a hex or separate RGB decimal values?


Submitted via EggHeadCafe - Software Developer Portal of Choice
XML into Data Islands Direct from SQL Server 2000
http://www.eggheadcafe.com/tutorials...lands-dir.aspx
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Another possibility

....or how to convert the RGB "Clr" value to a ColorIndex value using the workbook's default palette?



Craig Remillard wrote:

Hide columns according to background fill color
10-Jan-10

I am having trouble understanding how Excel handles colors.

I have a public sub that sets a public variable, "TermColor" using the RGB function. TermColor is of type MsoRGBType.

In another module, I use the TermColor variable as follows:

Sub WeedColsByColor(ByRef Clr, ByRef WS)

Dim LastCol, i As Long

With Worksheets(WS)

LastCol = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count

'hide columns if they have one of the forbidden colors
Debug.Print (CBool(.Cells(2, i).Interior.Color = Clr))
For i = 1 To LastCol
If .Cells(2, i).Interior.Color = Clr Then
.Cells(2, 1).EntireColumn.Hidden = True
End If '.Cells(2, i).Interior.Color = Color Then
Next i
End With 'Worksheets(WS)
End Sub

The debug statement gives me an error: Run-time error '1004': Application-defined or object-defined error

When I take the debug statement out and call the sub, I get nothing - no error, but also no columns are hidden. Using another debug statement, I am able to see that the IF statement is never entered.

Does anyone know either of the following:
1. How to phrase the IF statement so it compares cell color to Clr, or
2. How to output the .color and Clr to a hex or separate RGB decimal values?

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Content Director Test Article
http://www.eggheadcafe.com/tutorials...-test-art.aspx
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Another possibility

Without any testing at all...

LastCol = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
should probably be using .column and .columns.count



Craig, Remillard wrote:

...or how to convert the RGB "Clr" value to a ColorIndex value using the workbook's default palette?

Craig Remillard wrote:

Hide columns according to background fill color
10-Jan-10

I am having trouble understanding how Excel handles colors.

I have a public sub that sets a public variable, "TermColor" using the RGB function. TermColor is of type MsoRGBType.

In another module, I use the TermColor variable as follows:

Sub WeedColsByColor(ByRef Clr, ByRef WS)

Dim LastCol, i As Long

With Worksheets(WS)

LastCol = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count

'hide columns if they have one of the forbidden colors
Debug.Print (CBool(.Cells(2, i).Interior.Color = Clr))
For i = 1 To LastCol
If .Cells(2, i).Interior.Color = Clr Then
.Cells(2, 1).EntireColumn.Hidden = True
End If '.Cells(2, i).Interior.Color = Color Then
Next i
End With 'Worksheets(WS)
End Sub

The debug statement gives me an error: Run-time error '1004': Application-defined or object-defined error

When I take the debug statement out and call the sub, I get nothing - no error, but also no columns are hidden. Using another debug statement, I am able to see that the IF statement is never entered.

Does anyone know either of the following:
1. How to phrase the IF statement so it compares cell color to Clr, or
2. How to output the .color and Clr to a hex or separate RGB decimal values?

Previous Posts In This Thread:

Submitted via EggHeadCafe - Software Developer Portal of Choice
Content Director Test Article
http://www.eggheadcafe.com/tutorials...-test-art.aspx


--

Dave Peterson
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
Fill background color automatically by typing a letter in a cell Myke Excel Discussion (Misc queries) 5 April 22nd 23 12:10 AM
Excel doesn't print the background fill color chosen for a cell Joe Palazzo Excel Worksheet Functions 3 December 16th 08 03:20 PM
Fill Part of Chart Background with second color DQuint Excel Discussion (Misc queries) 2 April 6th 07 09:28 PM
tab background fill - color DeAnne New Users to Excel 4 October 24th 05 11:34 PM
Fill Color? Background Color? andy[_4_] Excel Programming 1 July 9th 03 09:50 PM


All times are GMT +1. The time now is 07:16 AM.

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

About Us

"It's about Microsoft Excel"