PDA

View Full Version : Compare rows with first row and copy the matching records in another sheet.



Arun
02-22-2012, 05:17 PM
Hello All Gurus,

I am in need of some help of VBA code (macro) which can help in how tocompare the row's in a sheet against first row which has string.

Note - Same file is attached in the mail which has the sheet 1 as input andsheet 2 as output.

I want to compare row 2,3,4,5 and so on .... till say 200th row with firstrow, and if the match if correct then in sheet2 set its value to 1 an if it ifalse then set its value to 0.

In addition to that in sheet2 i want to copy column B and C values which canbe referred from sheet1.

In addition to this in sheet2 give a sum in column AB for the row startingfrom column C to AA.

I will be very thankful to all of you guys for your efforts into this inadvance and all help will be truly appreciated.

Kindly help me . Thanks in advance

raji2678
02-22-2012, 10:04 PM
I can answer a part of your question. try using the vlookup formula, to see if any items in sheet1 are present in sheet2

Arun
02-22-2012, 10:48 PM
Hello Raji,

Thanks for providing feedback and your time. No i have nothing to do with sheet2 as sheet2 is my output sheet, only the thing in sheet 2 i want is total column and sum of all of the row count.

I have the input in sheet1 which will work based on condition -

1- Compare row 2,3,4,5 and so on till 200 with row1 (cell by cell) and if match is found then in sheet 2 keep on marking it 1 and if exact match is failed then mark it 0 starting from column c in sheet2.
I need to start reading the input data from sheet 1 starting from column D1,E1,F1 till AB1, same applies to D2,E2,F2 till AB2 till D200,E200,F200 till AB200.

2- In output sheet sheet2, add on extra column to make a count of row. Like if C2,D2,E2......................AA2 have sum of 7 then in AB1 enter 7….same applies for C3,D3,E3…………………………AA3 and so on till C200,D200,E200………………..AA200.

3- In output sheet sheet2 I need to copy the first two columns A/B (A1,B1, A2,B2……A200,B200) from column B/C (B1,C1, B2,C2……B200,C200) of sheet1.

For values/string it will be something like as I attached in the sample xls.

Kindly help me.

Thanks

raji2678
02-22-2012, 11:04 PM
Can you exactly state what you want to do? I feel that there can be a simpler way of doing it without following the steps you have mentioned. Correct me if I am wrong.

Arun
02-23-2012, 08:42 AM
I want the things in the form of macro, button click. My sheet1 is defined but set of values may change.

Raji what could be other ways ? Vlookup and other formulas ?

raji2678
02-23-2012, 09:09 PM
That is a possibility, along with pivots. But kindly state what is your objective.

Arun
02-24-2012, 04:57 AM
Objective is that i get the answers in the form of excel as what i have attached, and now i have to verify them .....if i do it using some formulas then i need to take some extra care of in case formulas are well in placed or not. Questions will remain constant ...say 25 but yes number of participants may increase or decrease.

Due to this if i get the answers in sheet 1 , i want to make a click/run a macro which will do all verification and provide the summarized data in sheet 2.

Correct answer are always in row 1 and now i have to compare the remaining rows with row 1 for correct answers. Along with this i thought of making a total also in the same event so that i need not to total the correct answers for each and every row.

Arun
03-01-2012, 11:59 AM
Somebody please help me with this ...some senior members ..xld plz help.
Thanks in advance to all of you for your time..