PDA

View Full Version : insert function in column



Nader
02-15-2008, 10:57 PM
Please take a look to the pic in the first
1- I want to insert the function Sumif or Sumproduct or any function in column H in sheet3 to sum the cells' H columns of sheet2 in condition only sum the cells of 4 match columns .
2- Insert in the last cells of 5, 6, 7 columns of sheet2 (which match the 4 columns in sheet2 with 4 columns in sheet3) in 5, 6, 7 columns of sheet3


As it show in the pic below.


I hope I'm clear


And thank you for help

Bob Phillips
02-16-2008, 04:31 AM
=SUMPRODUCT(--(Sheet2!$A$1:$A$10=A1),--(Sheet2!$B$1:$B$10=B1),--(Sheet2!$C$1:$C$10=C1),--(Sheet2!$D$1:$D$10=D1),Sheet2!$H$1:$H$10)

Nader
02-16-2008, 05:21 AM
wonderful thank you very mush... can you complete the sub please. I want a code to insert the function in match 4 columns in sheet3 in comparing with sheet2
as it show in this code for one matach column. this code I was got it from here.
Dim LastRow As Long
LastRow = Sheets("Sheet3").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Sheet3").Range("B1:B" & LastRow).Formula = "=SUMIF(Sheet2!A:A, A1, Sheet2!B:B)"

-and complete the second requiermrnt "2- Insert in the last cells of 5, 6, 7 columns of sheet2 (which match the 4 columns in sheet2 with 4 columns in sheet3) in 5, 6, 7 columns of sheet3". it's mean:
1 rwo in sheet 2 include K K K K H J K , 6 rwo include K K K K D P S .. so the sheet 3 every time will take the last cells of match columns in sheet2 it will copy K K K K D P S
I hope I'm clear..
And thank you again.

Bob Phillips
02-16-2008, 05:42 AM
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow2 As Long
Dim LastRow3 As Long
Dim TargetRow As Long

With Application

.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

With Worksheets("Sheet3")

LastRow3 = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row

.Range("H1").Resize(LastRow3).Formula = "=SUMPRODUCT(--(Sheet2!$A$1:$A$10=A1),--(Sheet2!$B$1:$B$10=B1),--(Sheet2!$C$1:$C$10=C1),--(Sheet2!$D$1:$D$10=D1),Sheet2!$H$1:$H$10)"
End With

With Worksheets("Sheet2")

LastRow2 = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To LastRow2

TargetRow = 0
On Error Resume Next
TargetRow = .Evaluate("MATCH(1,(Sheet3!A1:A" & LastRow3 & "=A" & i & ")*" & _
"(Sheet3!B1:B" & LastRow3 & "=B" & i & ")*" & _
"(Sheet3!C1:C" & LastRow3 & "=C" & i & ")*" & _
"(Sheet3!D1:D" & LastRow3 & "=D" & i & "),0)")
On Error GoTo 0
If TargetRow > 0 Then

Worksheets("Sheet3").Cells(TargetRow, "E").Resize(, 3).Copy .Cells(i, "E")
End If
Next i
End With

With Application

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub

Nader
02-16-2008, 07:32 AM
in the Sub ProcessData
for the first request to insert sumproduct has succeed with me.
For the second request didn't succeed with me. "May be I wasn't clear ", it copy the cells of 5,6,7 columns of sheet 3 to 5,6,7 columns of sheet2 but I want to copy the last(match 4 columns) 5,6,7 columns of sheet 2 to 5,6,7 columns of sheet3, as it show in the Pic below.

Thank you again for help

Nader
02-16-2008, 07:39 AM
Here is the exl file "book"

Bob Phillips
02-16-2008, 05:25 PM
How do you know to replace them with row 6 not row 1, they both have KKKK in A:D?

Nader
02-16-2008, 06:35 PM
If you consider them the last row of kkkk.

Nader
02-29-2008, 04:45 AM
I apologize for Xld!, because I didn't know how to deal with this code . I tried the code agian and it's work well with me.
Thank you! again Xld.