VBA Code which Search and find the value to be copied

ExcelMentee

Banned - Rules violations
Joined
Jan 11, 2021
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Looking for a VBA code which performs the following action.

That If Sheet1.Range("A1").Value = 2002_2550 or Text or Number

then Find that value in Sheet2.Range("A:A") If that number Matches then then copy the same cell of Col"B"

and then paste copied value in to Sheet3.Range("C15") till the ColB used range.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If that number Matches then then copy the same cell of Col"B" and then paste copied value in to Sheet3.Range("C15") till the ColB used range.

This part is not clear. Say you find match in Sheet2 column A in row 9 (for example).
Then copy what in column B? Start from range B9 until end of data row to sheet3("C15")?
 
Upvote 0

Zot, thank you for the response. Please have a look below​


I have this number in Sheet1
1611309675971.png


Code will find that Sheet1 value in Sheet2 Col"A" then copy the Col"B" value that is "156". (If that number Matches then then copy the same cell of Col"B")
1611309776267.png


After that code will paste that "156" VALUE IN Sheet3.Range("C2") to till where Col"B" used range end. (and then paste copied value in to Sheet3.Range("C15") till the ColB used range.|)

1611310034347.png
 
Upvote 0
I have no idea if the value in sheet1 is only one or many and always at B4. So, assume at B4.
For used range in sheet3, I just refer to end of row in column B as last filled range starting from C15.

VBA Code:
Sub Search_Transfer()

Dim cell As Range, rngData As Range, rngPaste
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet

Set ws1 = ActiveWorkbook.Sheets("Sheet1")
Set ws2 = ActiveWorkbook.Sheets("Sheet2")
Set ws3 = ActiveWorkbook.Sheets("Sheet3")

Set rngUsedRow = ws2.Range("A1", ws2.Range("A" & ws2.Rows.Count).End(xlUp))

For Each cell In rngUsedRow
    If cell = ws1.Range("B4") Then
        Set rngPaste = ws3.Range("B15", ws3.Range("B" & ws3.Rows.Count).End(xlUp)).Offset(0, 1)
        rngPaste.Value = cell.Offset(0, 1)
        Exit For
    End If
Next

End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,215,432
Messages
6,124,856
Members
449,194
Latest member
HellScout

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