Can anyone help I am new to VBA or I copy and paste then test? Below should be a basic way to find rows that match 3 criteria from row 1, work out the average to each column G to M of all the rows that match the criteria and copy and past to a repot sheet.
How can I find or match to multiple criteria
Private Sub Average() ' Application.ScreenUpdating = False Call Openreport Sheets("Data").Select 'Needs to be variable range Range("A8:P1413").Select Range(Selection, Selection.End(xlDown)).Select 'Copy and paste main data for manipulation Selection.copy Sheets("AV").Select Range("A2").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False 'Sort columns by Catagory of Company then by Company Name and then by region scoring Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, _ Key2:=Range("E2"), Order2:=xlAscending, _ Key3:=Range("C2"), Order3:=xlAscending, _ Header:=xlNo, _ OrderCustom:=1, _ MatchCase:=False, _ Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, _ DataOption2:=xlSortNormal, _ DataOption3:=xlSortNormal Range(ActiveCell, ActiveCell.Offset(Range(0), 5)).Select Selection.copy Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ' '1 copy paste row 2 to row 1 in sheet "AV" '2 Find first row that matches F1,E1,C1 after row 1 '3 If match found, copy row 2 to sheet "AVE" to the first empty row '4 delete row 2 in sheet "AV" '5 loop stage 1 '6 If no match found '7 copy row 1 in sheet "AVE" (range G1:M1 sum average down on sheet to give total average score) 'to first empty row in sheet "AVER" '8 delete rows not empty after row 3 in sheet "AVE" '9 Loop stage 1 until row 2 empty ' Do Until IsEmpty(ActiveCell) 'Need find all maybe 'Needs to be veriable range Range("A2:F?").Find(what:=Cells(F1, E1, C1), LookAt:=xlWhole, _ LookIn:=xlValues, _ searchorder:=xlByColumns).Activate 'If Match found Then ActiveCell.EntireRow.Select Selection.copy Sheets("AVE").Select Do Until IsEmpty(ActiveCell) Selection.Offset(1, 0).Select Loop Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("AV").Select ActiveCell.EntireRow.Delete 'Else If IsEmpty(ActiveCell) Then Call AV_Report Else Sheets("AVE").Select Range("A1").Select ActiveCell.EntireRow.Select Selection.copy Sheets("AVER").Select Do Until IsEmpty(ActiveCell) Selection.Offset(1, 0).Select Loop Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("AV").Select Range("A2").Select Range(ActiveCell, ActiveCell.Offset(Range(0), 5)).Select Selection.copy Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End If 'End If Loop Call Closereport Application.ScreenUpdating = True End Sub
Last edited by OpusOpus; 04-02-2010 at 04:01 PM. Reason: Desperation, Got it?
Welcome to the forum.
Please take a few minutes to read the forum rules, and then amend your thread title accordingly.
Thanks.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
When you read the rules also make sure you pay attention to the one about cross posting.
Next time make sure you post a link.
http://www.mrexcel.com/forum/showthread.php?t=459288
Also, five hours without a response doesn't mean all hope is lost on this, or any other forum.
DominicB
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks