Once the value match then copy from Sheet 1 specific cell & paste to another Sheet 2 a specific cell

Dharmesh Sabalpara

New Member
Joined
Nov 16, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
HI There,

Need Urgent Help to Build a Code for one Work project
workbook I need once cell value Matched wi Once the value match from Sheet 1 Cell5 to Sheet 2 range (A4:A7) then copy from Sheet 1 Cell ("C9", "E9","G9") a specific cell &
paste to a specific cell Like Below Example
Sheet 1 Cell value is "Rajesh"
In Sheet 2 Once the value is matched then on the same line a specific cell ("B5","D5","F9")

I already tried Below Code

Sub findAndCopy()
Dim foundCell As Range, sh1, sh2 As Worksheet

'Set sheets
Set sh1 = Sheets("Test-01")
Set sh2 = Sheets("Test-02")

'Find string in column C of Sheet2
Set foundCell = sh2.Range("A2:A5").Find(sh1.Range("D5").Value, , xlValues, xlWhole)
If Not foundCell Is Nothing Then 'If match cell is found
sh1.Range("C9", "E9").Copy
foundCell.PasteSpecial xlPasteValues
foundCell.PasteSpecial xlPasteFormats

Application.CutCopyMode = False
Else
Call MsgBox("Not found the match cell!", vbExclamation, "Finding String")
End If
End Sub
 

Attachments

  • Sheet-01.jpg
    Sheet-01.jpg
    34.4 KB · Views: 27
  • Sheet-02.jpg
    Sheet-02.jpg
    31.5 KB · Views: 27

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the Board!

See if this does what you want (it seems to work for me when run against the example you posted):
VBA Code:
Sub findAndCopy()
Dim foundCell As Range, sh1 As Worksheet, sh2 As Worksheet

'Set sheets
Set sh1 = Sheets("Test-01")
Set sh2 = Sheets("Test-02")

'Find string in column C of Sheet2
Set foundCell = sh2.Range("A2:A5").Find(sh1.Range("D5").Value, , xlValues, xlWhole)
If Not foundCell Is Nothing Then 'If match cell is found
    sh1.Range("C9:G9").Copy
    foundCell.Offset(0, 1).PasteSpecial xlPasteValues
    foundCell.Offset(0, 1).PasteSpecial xlPasteFormats
    Application.CutCopyMode = False
Else
    Call MsgBox("Not found the match cell!", vbExclamation, "Finding String")
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

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