Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default macros code & color based functions help

Hi there,

I'm working on an attendance spreadsheet and need some help since this is
my first time working with macros.

1. I'd like to tally up the sum of certain colored cells. I found this
link: http://cpearson.com/excel/colors.htm whicch leads me to believe that
this sort of function is possible. I tried copying and pasting the code
into a module and it won't run. Here is the code I entered into the module:

Function SumByColorV(InRange As Range, WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Double

Dim Rng As Range
Dim OK As Boolean

Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
OK = (Rng.Interior.ColorIndex = 39)
End If
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
End Function

Did I make a mistake somewhere? Also, the webpage says to call this
function =sumbycolorv (A1:A10, 3, False) in a worksheet cell. What does
the 3 and false represent?





2. I also want to change the color of a cell based on the first letter.
This webpage shows the forumula:

www.mvps.org/dmcritchie/excel/event.htm#case

And here is the code I entered into a module:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim vLetter As String
Dim vColor As Integer
Dim cRange As Range
Dim cell As Range

Set cRange = Intersect(Range("B3:X28"), Range(Target(1).Address))
If cRange Is Nothing Then Exit Sub

For Each cell In Target
vLetter = UCase(Left(cell.Value & " ", 1))
vColor = 0
Select Case vLetter
Case "V"
vColor = 39
Case "S"
vColor = 38
Case "E"
vColor = 3
Case "P"
vColor = 46
Case "T"
vColor = 34
Case "F"
vColor = 37
Case "W"
vColor = 50
Case "R"
vColor = 29
Case "L"
vColor = 41
End Select
Application.EnableEvents = False
cell.Interior.ColorIndex = vColor
Application.EnableEvents = True
Next cell
End Sub

Again, when I go to run the macro, it doesn't show up. Where is there a
mistake in the code?

If it helps, I can email you the worksheet so you can take a look yourself.

I really appreciate any help/advice.

Sincerely,
kim

--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default macros code & color based functions help

With only your workbook open, go to the VBE (alt+F11) and go to the menu.
Do Insert module.

Paste the code in the resulting module (I suspect you have used a sheet
module - remove it from there.)

No lines should show in Red.

The 3 means Red - count colors that are red. You can see the colors by
running a macro like this (have a blank worksheet active)

Sub ShowColorIndexes()
Dim i as Long
for i = 1 to 56
cells(i,1).Value = i
cells(i,2).Interior.ColorIndex = i
Next
End Sub

Place the above in a general module (same as you have). The go to
Tools=Macro=Macros, select it (ShowColorIndex) and click Run.


The True/False as the last argument means - if False, look at the cell's
interior color, and if it is true look at the cells font color.

However, you have modified Chips code so it only looks at the interior color
and it only looks at colorindex 39.

since you have not modified the declaration you need to at least do

=SumbyColor(A1:A10,39)

Mail the worksheet to

--
Regards,
Tom Ogilvy


"Kim via OfficeKB.com" wrote in message
...
Hi there,

I'm working on an attendance spreadsheet and need some help since this is
my first time working with macros.

1. I'd like to tally up the sum of certain colored cells. I found this
link:
http://cpearson.com/excel/colors.htm whicch leads me to believe that
this sort of function is possible. I tried copying and pasting the code
into a module and it won't run. Here is the code I entered into the

module:

Function SumByColorV(InRange As Range, WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Double

Dim Rng As Range
Dim OK As Boolean

Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
OK = (Rng.Interior.ColorIndex = 39)
End If
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
End Function

Did I make a mistake somewhere? Also, the webpage says to call this
function =sumbycolorv (A1:A10, 3, False) in a worksheet cell. What does
the 3 and false represent?





2. I also want to change the color of a cell based on the first letter.
This webpage shows the forumula:

www.mvps.org/dmcritchie/excel/event.htm#case

And here is the code I entered into a module:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim vLetter As String
Dim vColor As Integer
Dim cRange As Range
Dim cell As Range

Set cRange = Intersect(Range("B3:X28"), Range(Target(1).Address))
If cRange Is Nothing Then Exit Sub

For Each cell In Target
vLetter = UCase(Left(cell.Value & " ", 1))
vColor = 0
Select Case vLetter
Case "V"
vColor = 39
Case "S"
vColor = 38
Case "E"
vColor = 3
Case "P"
vColor = 46
Case "T"
vColor = 34
Case "F"
vColor = 37
Case "W"
vColor = 50
Case "R"
vColor = 29
Case "L"
vColor = 41
End Select
Application.EnableEvents = False
cell.Interior.ColorIndex = vColor
Application.EnableEvents = True
Next cell
End Sub

Again, when I go to run the macro, it doesn't show up. Where is there a
mistake in the code?

If it helps, I can email you the worksheet so you can take a look

yourself.

I really appreciate any help/advice.

Sincerely,
kim

--
Message posted via http://www.officekb.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default macros code & color based functions help

Hi Tom,

I just emailed you an example of the spreadsheet.

Thanks,
kim

--
Message posted via http://www.officekb.com
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
More Functions based on Font Color michelle New Users to Excel 2 September 3rd 08 08:56 PM
color code cells based on golddigger formula Network Guru Excel Discussion (Misc queries) 2 March 23rd 06 03:47 AM
Can I make if functions based on fill color? nickclingan Excel Discussion (Misc queries) 2 November 7th 05 10:44 PM
How do I color code a worksheet based on text Travis Littlechilds Excel Discussion (Misc queries) 2 May 31st 05 04:15 AM
how to color code a row of cells based on a specific cell value Parker1333 New Users to Excel 1 February 2nd 05 08:01 AM


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