Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Art Art is offline
external usenet poster
 
Posts: 587
Default Total amount By word

Hello:

I have the following chart:
A
1 1 Plastic 2 Wood 1 metal
2 5 Plastic 2 Metal
3 4 Metal 3 Wood

My question is, what is the easiest way to get a total of the amount of
plastic in the whole column A? The total should be 6.

P.S. (In Cell A1 it says the whole thing, "1 Plastic 2 Wood 1 metal" and so
forth in each cell.)

Any help would be appriciated.

Thanks.

Art.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Total amount By word

Another UDF 'art' ...Assume your data will be in the same format. Numeric
value followed by text and each piece separated by space.....OR otherwise the
below UDF will return an error....

=Getcountfor(A1:A3,"plastic")

Function GetCountfor(varRange As Range, strSearch As String)
Dim varTemp As Range
Dim arrData As Variant
For Each varTemp In varRange
arrData = Split(varTemp.Text, " ")
For intTemp = 0 To UBound(arrData)
If UCase(Trim(arrData(intTemp))) = UCase(strSearch) Then
GetCountfor = GetCountfor + CInt("0" & arrData(intTemp - 1))
End If
Next
Next
End Function
--
If this post helps click Yes
---------------
Jacob Skaria


"art" wrote:

Hello:

I have the following chart:
A
1 1 Plastic 2 Wood 1 metal
2 5 Plastic 2 Metal
3 4 Metal 3 Wood

My question is, what is the easiest way to get a total of the amount of
plastic in the whole column A? The total should be 6.

P.S. (In Cell A1 it says the whole thing, "1 Plastic 2 Wood 1 metal" and so
forth in each cell.)

Any help would be appriciated.

Thanks.

Art.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Total amount By word

A similar approach to the one you used, but I believe this coding may be a
little bit more efficient...

Function GetCountFor(varRange As Range, strSearch As String) As Double
Dim X As Long
Dim C As Range
Dim Parts() As String
For Each C In varRange
Parts = Split(C.Value, " ")
For X = 1 To UBound(Parts) Step 2
If StrComp(Parts(X), strSearch, vbTextCompare) = 0 Then _
GetCountFor = GetCountFor + Parts(X - 1)
Next
Next
End Function

--
Rick (MVP - Excel)


"Jacob Skaria" wrote in message
...
Another UDF 'art' ...Assume your data will be in the same format. Numeric
value followed by text and each piece separated by space.....OR otherwise
the
below UDF will return an error....

=Getcountfor(A1:A3,"plastic")

Function GetCountfor(varRange As Range, strSearch As String)
Dim varTemp As Range
Dim arrData As Variant
For Each varTemp In varRange
arrData = Split(varTemp.Text, " ")
For intTemp = 0 To UBound(arrData)
If UCase(Trim(arrData(intTemp))) = UCase(strSearch) Then
GetCountfor = GetCountfor + CInt("0" & arrData(intTemp - 1))
End If
Next
Next
End Function
--
If this post helps click Yes
---------------
Jacob Skaria


"art" wrote:

Hello:

I have the following chart:
A
1 1 Plastic 2 Wood 1 metal
2 5 Plastic 2 Metal
3 4 Metal 3 Wood

My question is, what is the easiest way to get a total of the amount of
plastic in the whole column A? The total should be 6.

P.S. (In Cell A1 it says the whole thing, "1 Plastic 2 Wood 1 metal" and
so
forth in each cell.)

Any help would be appriciated.

Thanks.

Art.


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
total amount sajith New Users to Excel 2 January 23rd 09 10:21 AM
Set total amount for an equation..... hln Excel Discussion (Misc queries) 5 July 24th 08 06:21 AM
sales tax total amount from one cell amount to another cell ROSIEMSM Excel Discussion (Misc queries) 1 May 19th 07 03:15 PM
need a formula to get the total $ amount FPJ Excel Discussion (Misc queries) 5 January 31st 07 05:16 PM
How do I calculate Amount of Sales Tax from Total Amount? MikeS Excel Worksheet Functions 1 March 26th 05 07:49 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"