Search : in
By :

Macro/VBA needed to find, match, copy/paste

Last answer on Oct 21, 2009 11:58:11 am BST Yo, on Oct 19, 2009 7:48:40 pm BST 
 Report this message to moderators

Hello,

Ok so i've searched and searched and still haven't found code to do exactly what I need.
The macro needs to be able to search hundrends of cells in the same column (sheet1) and if a cell in that column matches the first cell in another worksheet (Sheet2), then the macro pastes the following cells (from the same row on sheet2) on sheet1 (same row but different column ).
So i'm basically trying to cut out of the work of matching text from two different worksheets and copying and pasting the related data into the same row.
I found this macro as a standard module (not sure how helpful it is, but could be a starting point).

Option Explicit
Sub CopyData()
Dim cell As Range
Dim rw As Long
For Each cell In Worksheets("PTR").Range("A:A").Cells
If cell <> "" Then
rw = Lookup(cell.Value)
If rw <> 0 Then
Worksheets("PTR").Cells(cell.Row, "L").Resize(, 4).Value = _
Worksheets("Reference").Cells(rw, "L").Resize(, 4).Value
End If
End If
Next
End Sub
Function Lookup(item As String) As Long
On Error Resume Next
Lookup = WorksheetFunction.Match(item, Worksheets("Reference").Range("A:A"),
False)
On Error GoTo 0
End Function

Configuration: Windows XP Internet Explorer 7.0

Best answers for « Macro/VBA needed to find, match, copy/paste » in :
Excel – Macro for copy & paste selected range Show Excel – Macro for copy & paste selected range Issue Solution Note Issue I have a summary of data by month in one sheet and the raw data in another sheet. Instead of creating multiple worksheets for my raw data for each month, I want...
Copy/Paste problems when using Firefox ShowCopy/Paste problems when using Firefox Pushow Adware Extensions It happens that sometimes, Firefox refuse to copy/paste items. Two assumptions can be made: Pushow Adware You have been infected by an adware, named pushow**.dll...
Quick Copy/Paste under Ubuntu ShowQuick Copy/Paste under Ubuntu Intro Uses: Intro Under Ubuntu there is a quicker alternative to make a Copy/Paste other than using the native CTRL V and CTRL C combinations . You simply select the target text (it is uploaded in...
Vi/Vim - Avoid tabs when making a copy/paste Show[VI/VIM] Avoid tabs when making a copy/paste By default, when you make a copy and paste in vi or vim (through an remote SSH session), it adds incremented tabs at each line. To solve this problem,simply type: set paste in the window or add the...
Download CopyTrans Suite ShowCopyTrans Suite is a set of practical tools for your Ipod or Iphone. It contains: · CopyTrans v2.37 · CopyTrans Photo v2.21 · iLibs v1.13 · iCloner v1.07 · CopyTrans Doctor v1.015 · CopyTrans Manager v0.720 · SyncGuardian...
Linux - The Vi editor ShowIntroduction to Vi Despite its very limited ergonomics, Vi i is one of the most popular text editors texte under Unix type systems (with Emacs and pico). Under Linux, there is a free version of Vi called Vim (Vi Improved). Vi (pronounced vee-eye)...

1

 Excelguru, on Oct 21, 2009 11:58:11 am BST
  • +1

Hello
you can do it without a macro
Put the below formula in B1 in sheet 2
=vlookup($A1,CELLREF-SHEET1,column(),false)

The syntax is VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)­ A wise man once said, 'I complained that I had no shoes unti­l I met a man who had no feet.'
I am interested in financial Modelling and custom excel deve­lopment with excel macros.

Reply to Excelguru