Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 28
Default Sort by color "NAME?" error

I have tried to sort by color using a VBA. It was successful on one
spreadsheet I am working on, but not on another. I keep getting the error
message "NAME?", and I don't know why. Any help would be appreciated.

Thank you

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Sort by color "NAME?" error

hi
it would help if you posted your code.

regards
FSt1

"Churley" wrote:

I have tried to sort by color using a VBA. It was successful on one
spreadsheet I am working on, but not on another. I keep getting the error
message "NAME?", and I don't know why. Any help would be appreciated.

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 28
Default Sort by color "NAME?" error

This is the VBA I used:
Function ColorIndexOfCell(Rng As Range, _
Optional OfText As Boolean, _
Optional DefaultAsIndex As Boolean = True) As Integer

Dim C As Long
If OfText = True Then
C = Rng.Font.ColorIndex
Else
C = Rng.Interior.ColorIndex
End If

If (C < 0) And (DefaultAsIndex = True) Then
If OfText = True Then
C = GetBlack(Rng.Worksheet.Parent)
Else
C = GetWhite(Rng.Worksheet.Parent)
End If
End If

ColorIndexOfCell = C

End Function


Function GetWhite(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = &HFFFFFF Then
GetWhite = Ndx
Exit Function
End If
Next Ndx
GetWhite = 0
End Function

Function GetBlack(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = 0& Then
GetBlack = Ndx
Exit Function
End If
Next Ndx
GetBlack = 0
End Function


"FSt1" wrote:

hi
it would help if you posted your code.

regards
FSt1

"Churley" wrote:

I have tried to sort by color using a VBA. It was successful on one
spreadsheet I am working on, but not on another. I keep getting the error
message "NAME?", and I don't know why. Any help would be appreciated.

Thank you

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Sort by color "NAME?" error

hi
chip pearson's color functions.
where do you have these functions installed. unless they are installed in an
open workbook such as a personal.xls, they wont be available to all files. if
you have them installed in the other workbook that they worked in and not the
workbook you are working in now, that is why you're having problems.

Regards
FSt1

"Churley" wrote:

This is the VBA I used:
Function ColorIndexOfCell(Rng As Range, _
Optional OfText As Boolean, _
Optional DefaultAsIndex As Boolean = True) As Integer

Dim C As Long
If OfText = True Then
C = Rng.Font.ColorIndex
Else
C = Rng.Interior.ColorIndex
End If

If (C < 0) And (DefaultAsIndex = True) Then
If OfText = True Then
C = GetBlack(Rng.Worksheet.Parent)
Else
C = GetWhite(Rng.Worksheet.Parent)
End If
End If

ColorIndexOfCell = C

End Function


Function GetWhite(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = &HFFFFFF Then
GetWhite = Ndx
Exit Function
End If
Next Ndx
GetWhite = 0
End Function

Function GetBlack(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = 0& Then
GetBlack = Ndx
Exit Function
End If
Next Ndx
GetBlack = 0
End Function


"FSt1" wrote:

hi
it would help if you posted your code.

regards
FSt1

"Churley" wrote:

I have tried to sort by color using a VBA. It was successful on one
spreadsheet I am working on, but not on another. I keep getting the error
message "NAME?", and I don't know why. Any help would be appreciated.

Thank you

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Sort by color "NAME?" error

That looks like my code. You need to put all the code in a regular code
module (in VBA, Insert menu, Module), not the ThisWorkbook module and not
one of the Sheet modules. Once you do that, the code can be run by bringing
up the Macros dialog (ALT F8), selecting the procedure name in the list, and
clicking "Run". That will work for the workbook that contains the code. If
you want to use this code for any open workbook, you can put it in a regular
module in your Pearsonal.xls workbook. Then, in the Macros dialog, select
"All Open Workbooks" in the "Macros In" ComboBox.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


"Churley" wrote in message
...
This is the VBA I used:
Function ColorIndexOfCell(Rng As Range, _
Optional OfText As Boolean, _
Optional DefaultAsIndex As Boolean = True) As Integer

Dim C As Long
If OfText = True Then
C = Rng.Font.ColorIndex
Else
C = Rng.Interior.ColorIndex
End If

If (C < 0) And (DefaultAsIndex = True) Then
If OfText = True Then
C = GetBlack(Rng.Worksheet.Parent)
Else
C = GetWhite(Rng.Worksheet.Parent)
End If
End If

ColorIndexOfCell = C

End Function


Function GetWhite(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = &HFFFFFF Then
GetWhite = Ndx
Exit Function
End If
Next Ndx
GetWhite = 0
End Function

Function GetBlack(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = 0& Then
GetBlack = Ndx
Exit Function
End If
Next Ndx
GetBlack = 0
End Function


"FSt1" wrote:

hi
it would help if you posted your code.

regards
FSt1

"Churley" wrote:

I have tried to sort by color using a VBA. It was successful on one
spreadsheet I am working on, but not on another. I keep getting the
error
message "NAME?", and I don't know why. Any help would be appreciated.

Thank you




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Sort by color "NAME?" error

Answered in your post of 15 minutes ago.

Have a little patience..........15 minutes is not a long time to wait for a
reply.


Gord Dibben MS Excel MVP
On Fri, 15 Feb 2008 08:37:02 -0800, Churley
wrote:

I have tried to sort by color using a VBA. It was successful on one
spreadsheet I am working on, but not on another. I keep getting the error
message "NAME?", and I don't know why. Any help would be appreciated.

Thank you


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
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
Shortcut key for "Paste Options" and "Error Checking" buttons? johndog Excel Discussion (Misc queries) 1 October 6th 06 11:56 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
pictures to work with "data" "sort" option arad Excel Discussion (Misc queries) 1 April 18th 06 09:15 PM
Any IF(A2=font color=red", "1", "0") in excel? Or a way to do it? Steve Excel Discussion (Misc queries) 1 November 7th 05 02:48 PM


All times are GMT +1. The time now is 09:48 PM.

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"