![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 5
|
Is there a way to sum numbers only if they are shaded in a certain color?
Thank you. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Do you have a problem with using a macro?
|
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Posts: 5
|
Thanks for responding. I am a novice; but I have recorded a few before. Never really used visual basic.
I am open. |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Try the following:
Sub SumShaded() Dim total As Long For Each cell In Selection If cell.Interior.ColorIndex <> xlNone Then _ total = total + cell.Value Next MsgBox "The total of the cells is " & total End Sub Repost if you need editting.
__________________
Kind regards, Al Chara |
|
|
|
|
|
#5 |
|
New Member
Join Date: May 2002
Posts: 5
|
Wow, thanks that was great. Not to be picky but if I could get the total to show cents as well and dollars and perhaps fix in on a certain range instead of having to highlight a range first.
Thanks again. |
|
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Quote:
|
|
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Anyway, try the following:
Sub SumShaded() Dim total As Currency For Each cell In Range("a1:a5") If cell.Interior.ColorIndex <> xlNone Then _ total = total + cell.Value Next MsgBox "The total of the cells is " & FormatCurrency(total) End Sub _________________ Hope this helps. Kind regards, Al. [ This Message was edited by: Al Chara on 2002-05-23 13:52 ] |
|
|
|
|
|
#8 |
|
New Member
Join Date: May 2002
Posts: 5
|
Thanks again.
It currently reads the total is 499 versus 498.47 As for range: E2:E250 Thanks |
|
|
|
|
|
#9 |
|
New Member
Join Date: May 2002
Posts: 5
|
That last one worked. I really appreciate your help. That will save me a lot of time.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|