Find and Update Value

smartguy

Well-known Member
Joined
Jul 14, 2009
Messages
778
Hello all,

I have excel file in the below .


Excel Workbook
CDEFGHI
1StudentMark1Mark2Mark3
21
32
43
54
65
76
87
98
109
1110
Sheet1



Sheet 2 i Have data.


Excel Workbook
EFGH
1StudentMark1Mark2Mark3
221012020
33232122
44342324
555762526
6622234345
77223290
Sheet2



I want to updated data in to sheet1.

Answer :


Excel Workbook
CDEFGHI
1StudentMark1Mark2Mark3
21
321012020
43232122
54342324
655762526
7622234345
87223290
98
109
1110
Sheet1



I am looking for VBA Code....
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I have to agree with Weaver here. There are much better methods of achieving this goal without using VBA here.
 
Upvote 0
Code:
Sub vlookupPlus()
    Dim sRange, dRange
    Application.ScreenUpdating = False
    With Sheets("sheet2")
        Set sRange = .Range("A2", .Cells(Rows.Count, 1).End(xlUp)).Resize(, 4)
    End With
    With Sheets("sheet1")
        Set dRange = .Range("G2", .Cells(Rows.Count, 3).End(xlUp).Offset(, 4)).Resize(, 3)
    End With
    With dRange
        .FormulaR1C1 = "=VLOOKUP(RC3,Sheet2!" & sRange.Address(, , 0) & ",COLUMN(Sheet2!R1C[-5]),0)"
        .Value = .Value
        .Replace "#n/a", ""
    End With
End Sub
 
Upvote 0
Hello ,

The Above code is not working....

From the fact that I wouldn't have posted it if it didn't work on my machine, you can assume that it did. Therefore a more descriptive response is required if you expect me to do anything about it.
 
Upvote 0
Try this slight variation.
Code:
Sub vlookupPlus()
    Dim sRange, dRange
    Application.ScreenUpdating = False
    With Sheets("sheet2")
        Set sRange = .Range("E2", .Cells(Rows.Count, 5).End(xlUp)).Resize(, 4)
    End With
    With Sheets("sheet1")
        Set dRange = .Range("G2", .Cells(Rows.Count, 3).End(xlUp).Offset(, 4)).Resize(, 3)
    End With
    With dRange
        .FormulaR1C1 = "=VLOOKUP(RC3,Sheet2!" & sRange.Address(, , 0) & ",COLUMN(Sheet2!R1C[-5]),0)"
        .Value = .Value
        .Replace "#n/a", ""
    End With
End Sub
 
Last edited:
Upvote 0
The error is because Weaver started sheet 2 in Column A and smartguy is starting in Column E
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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