Copy and Paste VBA Code

Grunt

New Member
Joined
Oct 10, 2005
Messages
30
Hi. I'm using Excel 2003 and having no sucess in writing a VBA code for the below. Appreciate any help I can get:


Look at the invoice numbers in column B of sheet X.

If any match the invoice numbers in column A of sheet Y

Copy the date in column V of sheet X of the match

And paste to the match in column D of sheet Y.


In this doesn't make sense let me know.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Code:
Public Sub test2()
 
    a = Application.Match(ActiveCell, Sheets("SheetY").Range("A:A"))
    b = Sheets("SheetX").Range(ActiveCell.Address).Offset(0, 20)
 
    If Not IsError(a) Then
        Sheets("SheetY").Range("D" & a) = _
            Sheets("SheetX").Range(ActiveCell.Address).Offset(0, 20)
 
    Else
        MsgBox "No matching invoice number found on ""SheetY""!"
    End If
 
End Sub

Run this with your cursor on the cell containing the invoice number you want to work with.
 
Upvote 0
Glory, many thanks for the response. I asserted the code, but cannot get it to work. I originally created a module and pasted the code there. I then went back to sheet X and made a macro and macro button called "run macro" and linked the button to the module. When I press the button I receive a "run-time error 9 subscript out of range" message. I believe the problem may relate to where I have the code. If correct please assist. Thanks- Grunt
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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