Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default sum the first number in a range

on 10th August 08 asked for help to sum first number in a range of
cells,Hector came up with this

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
MsgBox Evaluate("sumproduct(--left(0&" & myrange1.Address & ",2))")

And it works a treat, but I have been trying madly to get it to work using
the second letter in a cell in the range as a criterea for the sum to work.
Please Help or I shall start smoking again. Regards John L
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default sum the first number in a range

You need to use MID instead of Left to get the middle of a string. Mid
requires the start position of the character and the number of characters.

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
MsgBox Evaluate("sumproduct(--mid(0&" & myrange1.Address & ",1,1))")

"John LR" wrote:

on 10th August 08 asked for help to sum first number in a range of
cells,Hector came up with this

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
MsgBox Evaluate("sumproduct(--left(0&" & myrange1.Address & ",2))")

And it works a treat, but I have been trying madly to get it to work using
the second letter in a cell in the range as a criterea for the sum to work.
Please Help or I shall start smoking again. Regards John L

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default sum the first number in a range

Thanks for the answer Joel'
What I am trying to do is sum the left single number in a cell in a range ,
by using the mid(2,1) in the same cell as the criteria, eg if myrange1 cells
contain 2a.4a.5b. and the criteria is "a" then the answer is 6

"Joel" wrote:

You need to use MID instead of Left to get the middle of a string. Mid
requires the start position of the character and the number of characters.

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
MsgBox Evaluate("sumproduct(--mid(0&" & myrange1.Address & ",1,1))")

"John LR" wrote:

on 10th August 08 asked for help to sum first number in a range of
cells,Hector came up with this

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
MsgBox Evaluate("sumproduct(--left(0&" & myrange1.Address & ",2))")

And it works a treat, but I have been trying madly to get it to work using
the second letter in a cell in the range as a criterea for the sum to work.
Please Help or I shall start smoking again. Regards John L

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default sum the first number in a range

the VALUE on a worksheet works different then the VAL in VBA. The VBA
function will remove the number from the rest of the string.

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
If Mid(myrange1, 2, 1) = "a" Then

Total = 0
For Each num In myrange1
Total = Total + Val(num)
Next num

MsgBox Total
End If
End Sub


"John LR" wrote:

Thanks for your reply Joel ,but I am trying to use the second letter in the
range cells as the criteria to sum the first number along the line of

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
If mid(myrange1,2,1)="a" Then
MsgBox Evaluate("sumproduct(--left(0&" & myrange1.Address & ",2))")
End if
So if A1=5A, B1=6A,C1=5B Answer =11
Hope This is clear and some one can help. Regards John LR

"Joel" wrote:

You need to use MID instead of Left to get the middle of a string. Mid
requires the start position of the character and the number of characters.

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
MsgBox Evaluate("sumproduct(--mid(0&" & myrange1.Address & ",1,1))")

"John LR" wrote:

on 10th August 08 asked for help to sum first number in a range of
cells,Hector came up with this

Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
MsgBox Evaluate("sumproduct(--left(0&" & myrange1.Address & ",2))")

And it works a treat, but I have been trying madly to get it to work using
the second letter in a cell in the range as a criterea for the sum to work.
Please Help or I shall start smoking again. Regards John L

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
Max number in a given range pcor New Users to Excel 7 February 13th 08 01:11 AM
"PasteSpecial method of Range class failed" when range Number of Rows 2000 eskimo2 Excel Programming 0 October 19th 07 06:09 PM
Locate number within range, copy number below it to another cell [email protected] Excel Programming 3 October 17th 06 09:34 PM
Finding Number Within Range Then Copying Data Below Number to Cells [email protected] Excel Programming 5 October 16th 06 06:32 PM
Assign one number to a number range Sue New Users to Excel 1 October 6th 05 01:21 AM


All times are GMT +1. The time now is 12:06 AM.

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"