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: 14
Default Row parts and range confusion

Hi using matching to identify a particular cell, I want to search and sum the
range of the contents of a cell - in a different column for the same row.

e.g. I want to sum the range contained in cell H36 - e.g. "query!$M$2$M13$'
and I have already found the matching row by locating the single range cell
B36 which is set via Set rng2 = rng1(resFinal)

I set a particular cell as a range(rng2 is set to the value of B36) and then
try to refer to the same row but another column in the totals line

Can someone explain to me how ranges work e.g. what is Cells(rng2.Row,
"H").Value and why the totals line below is falling over
- I did not write it but when I run it the locals window blanks.

Many thanks again
Jello.


Public Function regionTotal(countryRng As String) As Long

Dim rng As Range
Dim rng1 As Range
Dim rng2 As Range

Dim Total As Long

Dim res1 As Variant
Dim res2 As Variant
Dim resFinal As Integer

Set rng = Range("calc!B10") ' Apples
Set rng1 = Range("calc!B33:B65") ' range to be searched
res1 = Application.Match("*" & rng & "*", rng1, 0)
res2 = Application.Match("*" & countryRng & "*", rng1, 0)

resFinal = Application.WorksheetFunction.Max(res1, res2)

If Not IsError(resFinal) Then
Set rng2 = rng1(resFinal)
Total = Application.WorksheetFunction.Sum(rng2.parent.Rang e( _
rng2.parent.Cells(rng2.Row, "H").Value).Value)
MsgBox Total & " for range: " & Cells(rng2.Row, "H").Value
Else
MsgBox Range("calc!B10").Value & " was not found"

End If

regionTotal = Total

End Function



 
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
Copy parts of a data range into a new spreadsheet forest8 Excel Worksheet Functions 4 April 21st 08 08:26 PM
MDI Confusion CMoya Excel Discussion (Misc queries) 1 February 21st 08 02:11 PM
COUNTIF in a range (and parts of cells) Phrank Excel Worksheet Functions 3 October 10th 06 10:51 AM
Confusion..... Eric @ CMN, Evansville Excel Discussion (Misc queries) 2 December 27th 05 07:15 PM
Vlookup of parts of a word in a range of Data Andre Croteau Excel Discussion (Misc queries) 3 December 19th 04 07:26 PM


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

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"