Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2007

Tip: Looking for answers? Try searching our database.

subtract only the highlighted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ganga - 05 Mar 2007 12:24 GMT
i just want to how can we subtract the highlighted ones from the total.

eg:
1256   sdkjfs
1236   dfsdf
2569    dfsdfs
2669    dfsdfs
3214    dfsdf
2200   sdfsdf
1230   dfsdfsdf
(total)
(total - highlighted)

when i highlight the 2nd column each time i want the 1st column to be
subtracted from the total(all the highlighted ones).

thank you
Gary''s Student - 05 Mar 2007 17:11 GMT
Assuming that your data is in A1 thru B7, enter and run this macro:

Sub ganga()
c1 = 0
c2 = 0

For i = 1 To 7
   If Cells(i, 2).Interior.ColorIndex = xlNone Then
       c1 = c1 + Cells(i, 1).Value
   Else
       c2 = c2 + Cells(i, 1).Value
End If
Next

Cells(8, 1).Value = c1
Cells(9, 1).Value = c2
End Sub

This will put the sum of the non-highlighted in A8
and the sum of the highlighted in A9
Signature

Gary''s Student
gsnu200709

> i just want to how can we subtract the highlighted ones from the total.
>
[quoted text clipped - 13 lines]
>
> thank you
Bernard Liengme - 05 Mar 2007 17:43 GMT
If you prefer a function to a subroutine:

Function NotLit(myrange)
 For j = 1 To myrange.Count / 2
  If myrange(j, 2).Interior.ColorIndex = xlNone Then
   mysum = mysum + myrange(j, 1)
  End If
Next j
NotLit = mysum
End Function

best wishes
Signature

Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

>i just want to how can we subtract the highlighted ones from the total.
>
[quoted text clipped - 13 lines]
>
> thank you
ganga - 13 Mar 2007 02:41 GMT
i have no idea how to do a subroutine..please be more specific..

thanks

> If you prefer a function to a subroutine:
>
[quoted text clipped - 25 lines]
> >
> > thank you
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.