Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Total newbie question involving pasting someone else's Macro


I want to be able to use this macro:

Function SumByColor(InRange As Range, WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Double
'
' This function return the SUM of the values of cells in
' InRange with a background color, or if OfText is True a
' font color, equal to WhatColorIndex.
'
Dim Rng As Range
Dim OK As Boolean

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

End Function

In my workbooks.

How do I do it, or where do I put it?

As you can probably tell, I have no clue how macros or VB work, jus
thought I'd jump in and ask the question....

Many thanks in advance,

Chri

--
Tibb
-----------------------------------------------------------------------
Tibbs's Profile: http://www.excelforum.com/member.php...fo&userid=1594
View this thread: http://www.excelforum.com/showthread.php?threadid=27427

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Total newbie question involving pasting someone else's Macro

Tibbs,

Use ALT+F11 to open the VBA Editor. In the editor, go to the
Insert menu and choose Module. This will open a code window on
the right side of the main editior window. Paste the code in
that window. Then, you can call the SumByColor function directly
from a worksheet cell with a formula like

=SumByColor(A1,6,False)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Tibbs" wrote in message
...

I want to be able to use this macro:

Function SumByColor(InRange As Range, WhatColorIndex As
Integer, _
Optional OfText As Boolean = False) As Double
'
' This function return the SUM of the values of cells in
' InRange with a background color, or if OfText is True a
' font color, equal to WhatColorIndex.
'
Dim Rng As Range
Dim OK As Boolean

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

End Function

In my workbooks.

How do I do it, or where do I put it?

As you can probably tell, I have no clue how macros or VB work,
just
thought I'd jump in and ask the question....

Many thanks in advance,

Chris


--
Tibbs
------------------------------------------------------------------------
Tibbs's Profile:
http://www.excelforum.com/member.php...o&userid=15947
View this thread:
http://www.excelforum.com/showthread...hreadid=274275



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Total newbie question involving pasting someone else's Macro

ToolsMacroVisual Basic Editor (you can see now that you could have keyed
ALT+F11)
InsertModule
Paste the code in the blank code window
ALT+F11 (again; it toggles between your spreadsheet and the macro code)
Now you can type the function call in a cell and see the result.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"Tibbs" wrote in message
...

I want to be able to use this macro:

Function SumByColor(InRange As Range, WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Double
'
' This function return the SUM of the values of cells in
' InRange with a background color, or if OfText is True a
' font color, equal to WhatColorIndex.
'
Dim Rng As Range
Dim OK As Boolean

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

End Function

In my workbooks.

How do I do it, or where do I put it?

As you can probably tell, I have no clue how macros or VB work, just
thought I'd jump in and ask the question....

Many thanks in advance,

Chris


--
Tibbs
------------------------------------------------------------------------
Tibbs's Profile:
http://www.excelforum.com/member.php...o&userid=15947
View this thread: http://www.excelforum.com/showthread...hreadid=274275



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
Newbie Macro Question rich Excel Discussion (Misc queries) 1 August 23rd 07 07:15 PM
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
total dumb newbie question ayla Excel Discussion (Misc queries) 1 November 30th 05 03:57 PM
Total question (macro?) cwilson Excel Programming 1 October 15th 04 07:36 PM
VBA question involving an InputBox Don Lindros Excel Programming 1 April 13th 04 01:04 PM


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