Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Sumif - For Each problem (several column comparison)

Hi,

I've got a problem. I need to compare two columns in one
sheet(1) with two columns in another sheet(2). If the
cells in several rows (column A&B) in one sheet(1) exactly
match a row in the other sheet(2) (column A&B), I like the
values in column C to be summarized in the second sheet(2).

(This is a part of a bigger problem and a PIVOT solution
is not applicable)

Sheet 1 (data) Sheet2 (result)
ColA ColB ColC ColA ColB ColC
Row1 AA BA 15 Row1 AA BA 25
Row2 AA BA 10 Row2 AB BA 5
Row3 AB BA 5

I'll tried a For each - sumif script, but did not succeed.
Se below:

Sub I_UpdateHours()
Dim rng As Range, rng1 As Range, cell As Range
Dim res As Variant

With Worksheets("Works")
Set rng = .Range(.Cells(2, 1), .Cells(Rows.Count, 2).End
(xlUp))
End With

With Worksheets("Database")
Set rng1 = .Range(.Cells(2, 33), .Cells(Rows.Count,
34).End(xlUp))
End With

For Each cell In rng
If Application.SumIf(rng1, cell.Value, rng1.Offset(0,
1)) = 0 Then
Else

cell.Offset(0, 2).Value = _
Application.SumIf(rng1, cell.Value, rng1.Offset(0, -
25))
End If
Next

End Sub

Appreciate any help to get this to work!

Thanks!
Mats W
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Sumif - For Each problem (several column comparison)

Hi
try using Sumproduct. See:
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

--
Regards
Frank Kabel
Frankfurt, Germany

"Mats W" schrieb im Newsbeitrag
...
Hi,

I've got a problem. I need to compare two columns in one
sheet(1) with two columns in another sheet(2). If the
cells in several rows (column A&B) in one sheet(1) exactly
match a row in the other sheet(2) (column A&B), I like the
values in column C to be summarized in the second sheet(2).

(This is a part of a bigger problem and a PIVOT solution
is not applicable)

Sheet 1 (data) Sheet2 (result)
ColA ColB ColC ColA ColB ColC
Row1 AA BA 15 Row1 AA BA 25
Row2 AA BA 10 Row2 AB BA 5
Row3 AB BA 5

I'll tried a For each - sumif script, but did not succeed.
Se below:

Sub I_UpdateHours()
Dim rng As Range, rng1 As Range, cell As Range
Dim res As Variant

With Worksheets("Works")
Set rng = .Range(.Cells(2, 1), .Cells(Rows.Count, 2).End
(xlUp))
End With

With Worksheets("Database")
Set rng1 = .Range(.Cells(2, 33), .Cells(Rows.Count,
34).End(xlUp))
End With

For Each cell In rng
If Application.SumIf(rng1, cell.Value, rng1.Offset(0,
1)) = 0 Then
Else

cell.Offset(0, 2).Value = _
Application.SumIf(rng1, cell.Value, rng1.Offset(0, -
25))
End If
Next

End Sub

Appreciate any help to get this to work!

Thanks!
Mats W


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
Column comparison Dave T New Users to Excel 4 May 24th 09 06:06 PM
Column Comparison and Like Rows Tom Moffatt[_2_] Excel Discussion (Misc queries) 1 June 20th 08 02:52 PM
Column Comparison Trouble RH Excel Worksheet Functions 2 November 1st 07 01:55 AM
Excel Chart - 2 column stack /w 1 comparison column wclairmont Charts and Charting in Excel 1 December 1st 06 01:54 AM
sumif based on cell comparison in excel Bunty Excel Worksheet Functions 2 November 13th 06 03:38 PM


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