LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default wrap text

Try this:

Function SumValuesInCell(WrappedText As String) As Double
Dim Vals As Variant
Dim sum As Double, i As Long

WrappedText = Replace(WrappedText, vbCr, "")
Vals = Split(WrappedText, vbLf)
For i = 0 To UBound(Vals)
sum = sum + Val(Trim(Vals(i)))
Next i
SumValuesInCell = sum
End Function

Function SumAll(R As Range) As Double
Dim cl As Range
Dim sum As Double
For Each cl In R.Cells
sum = sum + SumValuesInCell(cl.Value)
Next cl
SumAll = sum
End Function

Enter this into a general code module. Then in your example,
=SumAll(A1:A4) used as a user-defined spreadsheet function (put say in
A5) will yield 3991 (as it should). It could also be called in another
macro via something like SumAll(Range("A1:A4"))

This code works in Windows. It will also work in MAC OS X and above. If
for some reason you are using Excel in Macs with an older operating
system this code won't work because of the way those systems handled
newlines.

Hope that helps

-John Coleman

bijan wrote:
I have a huge data that some of them contain wrap text cells with number value,
how I can sum this example correctly with macro?
A B
1 10
20
2 54
3 3365
18
4 524


 
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
How do I get date/time to wrap (format - wrap text doesn't work)? Alex Excel Discussion (Misc queries) 3 April 4th 23 02:29 PM
Excel 2007; even though "Wrap Text" is on the text does wrap? Bruce M[_2_] Excel Discussion (Misc queries) 0 December 31st 09 02:58 PM
Wrap text doesn't wrap [email protected] Excel Worksheet Functions 1 March 28th 07 01:58 AM
Why won't text in cell wrap. Cell format set to wrap. DRB Excel Discussion (Misc queries) 2 September 28th 06 08:27 PM
Text not continuing to wrap for large block of text in Excel cell Mandra Charts and Charting in Excel 1 May 15th 06 07:13 PM


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