Need Small change in this macro

gameover

Active Member
Joined
Jan 12, 2009
Messages
292
Hi All,
I need some changes in below code. This code compare column A in 2 sheets and copy values which are present in Column B and C of 2nd sheet. What I need is that macro compares columns A, B and C in both sheet and if all values are same then it copies value in column D and paste in sheet 1. Any ideas…….Thanks a lot for your time and answers.
PHP:
' ws1 and ws2 are worksheet objects. Set them to point to the sheets.
'ws2 is updated sheet
'ws1 is the sheet where values are updated by the code.

For Each cell In ws2.Range("A1:A" & ws2.Range("A1048576").End(xlUp))
    If cell = "" Then GoTo nextVal
    Set rng1 = ws1.Range("A1").EntireColumn.Find(cell)
    If rng1 Is Nothing Then GoTo nextVal
    ws1.Cells(rng1.Row, rng1.Column + 1) = ws2.Cells(cell.Row, cell.Column + 1)
    ws1.Cells(rng1.Row, rng1.Column + 2) = ws2.Cells(cell.Row, cell.Column + 2)
   
nextVal:
Next
 
This is how my table's sheet 1 look like:

Cust Id
Half
Year
Result
1
H1
2007

1
H1
2007

2
H2
2008

3
H1
2009

2
H2
2008


<tbody>
</tbody>

This is what sheet 2 contains
Cust Id
Half
Year
Result
1
H1
2007
New
1
H2
2007
Old
2
H1
2008
Old
3
H1
2009
New
3
H1
2008
New

<tbody>
</tbody>

This is how the end result should look like:
Cust Id
Half
Year
Result
1
H1
2007
New
1
H1
2007
New
2
H2
2008
Old
3
H1
2009
New
2
H2
2008
0 or NA

<tbody>
</tbody>

But after using your macro the result is
Cust Id
Half
Year
Result
1
H1
2007
ResultNew
1
H1
2007
ResultNew
2
H2
2008
ResultNew
3
H1
2009
ResultNew
2
H2
2008
0

<tbody>
</tbody>
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I am sorry I have taken your so much time... :(

No problem.
You are using tables are you?
Not sure why this occurs, you could try amending the formula yourself tho. By not using the first row of your sheet. Its very hard to get it right without having the workbook myself :)

Would have solved it quickly otherwise I think. Any way you could send it? I can PM you my mail addr.
 
Upvote 0

Forum statistics

Threads
1,215,483
Messages
6,125,065
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top