Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default SORTING BY COLOR

I am trying to sort rows by color. I have created a column for ColorIndex and
then created the following VBA code.

Function ColorIndexOfCell(Rng As Range, Optional OfText As Boolean, Optional
DefaultAsIndex As Boolean = True) As Integar

Dim C As Long
If OfText = True Then
C = Range("c1:c10").Font.ColorIndex
Else
C = Range("c1:c10").Interior.ColorIndex
End If

If (C < 0) And (DefaultAsIndex = True) Then
If OfText = True Then
C = GetBlack(Range("c1:c10").Worksheet.Parent)
Else
C = GetWhite(Range("c1:c10").Worksheet.Parent)
End If
End If

ColorIndexOfCell = C

End Function

When I put the following formula into a cell of the Colorindex column

=COLORINDEXOFCELL(A1,TRUE,TRUE)

I get a compile error message "User-defined type not defined". Hopefully
it's a simple error, I am fairly new to VBA programming.

--
Marshall
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default SORTING BY COLOR

Hi Marshall,

I get a compile error message "User-defined type not defined". Hopefully
it's a simple error, I am fairly new to VBA programming.


Try changing

Function ColorIndexOfCell(Rng As Range, Optional OfText As Boolean,
Optional
DefaultAsIndex As Boolean = True) As Integar


to

Function ColorIndexOfCell(Rng As Range, _
Optional OfText As Boolean, _
Optional DefaultAsIndex As Boolean = True) As Integer

(Integar == Integer).

There are, however, other proble,s with your function; no least that you do
not use the rng argument in the function and, instead use a hardcoded range.

For an alternative implementation, see xlDynamic at:

http://www.xldynamic.com/source/xld....r.html#sorting


---
Regards,
Norman



"Marshall Scmidt" wrote in
message ...
I am trying to sort rows by color. I have created a column for ColorIndex
and
then created the following VBA code.

Function ColorIndexOfCell(Rng As Range, Optional OfText As Boolean,
Optional
DefaultAsIndex As Boolean = True) As Integar

Dim C As Long
If OfText = True Then
C = Range("c1:c10").Font.ColorIndex
Else
C = Range("c1:c10").Interior.ColorIndex
End If

If (C < 0) And (DefaultAsIndex = True) Then
If OfText = True Then
C = GetBlack(Range("c1:c10").Worksheet.Parent)
Else
C = GetWhite(Range("c1:c10").Worksheet.Parent)
End If
End If

ColorIndexOfCell = C

End Function

When I put the following formula into a cell of the Colorindex column

=COLORINDEXOFCELL(A1,TRUE,TRUE)

I get a compile error message "User-defined type not defined". Hopefully
it's a simple error, I am fairly new to VBA programming.

--
Marshall



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default SORTING BY COLOR

Hi Norman,

Many thanks for your help. I've just accessed the site you suggested.
--
Marshall


"Norman Jones" wrote:

Hi Marshall,

I get a compile error message "User-defined type not defined". Hopefully
it's a simple error, I am fairly new to VBA programming.


Try changing

Function ColorIndexOfCell(Rng As Range, Optional OfText As Boolean,
Optional
DefaultAsIndex As Boolean = True) As Integar


to

Function ColorIndexOfCell(Rng As Range, _
Optional OfText As Boolean, _
Optional DefaultAsIndex As Boolean = True) As Integer

(Integar == Integer).

There are, however, other proble,s with your function; no least that you do
not use the rng argument in the function and, instead use a hardcoded range.

For an alternative implementation, see xlDynamic at:

http://www.xldynamic.com/source/xld....r.html#sorting


---
Regards,
Norman



"Marshall Scmidt" wrote in
message ...
I am trying to sort rows by color. I have created a column for ColorIndex
and
then created the following VBA code.

Function ColorIndexOfCell(Rng As Range, Optional OfText As Boolean,
Optional
DefaultAsIndex As Boolean = True) As Integar

Dim C As Long
If OfText = True Then
C = Range("c1:c10").Font.ColorIndex
Else
C = Range("c1:c10").Interior.ColorIndex
End If

If (C < 0) And (DefaultAsIndex = True) Then
If OfText = True Then
C = GetBlack(Range("c1:c10").Worksheet.Parent)
Else
C = GetWhite(Range("c1:c10").Worksheet.Parent)
End If
End If

ColorIndexOfCell = C

End Function

When I put the following formula into a cell of the Colorindex column

=COLORINDEXOFCELL(A1,TRUE,TRUE)

I get a compile error message "User-defined type not defined". Hopefully
it's a simple error, I am fairly new to VBA programming.

--
Marshall




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SORTING BY COLOR


Hi, your problem is probably caused by your function line that ends wit
the word Integar but should be Integer.

Regards,
Simo

--
Simon Lloy
-----------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...nfo&userid=670
View this thread: http://www.excelforum.com/showthread.php?threadid=57170

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
Sorting CF Color Johnny1r Excel Worksheet Functions 3 March 16th 08 11:34 AM
Sorting by color FARAZ QURESHI Excel Discussion (Misc queries) 2 December 28th 06 10:58 PM
Sorting by color aposatsk Excel Discussion (Misc queries) 1 August 9th 06 03:06 PM
Sorting by color blueglass74 Excel Discussion (Misc queries) 4 February 26th 06 05:21 PM
Sorting by color? Dave@Penske Excel Worksheet Functions 3 November 12th 04 07:13 PM


All times are GMT +1. The time now is 02:15 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"