Automate copy/paste/print via macros/vba

Stephen_W

New Member
Joined
Dec 2, 2016
Messages
1
Hello,
Relatively simple task to complete but new to macros/vba. I have a spreadsheet containing a wealth of data and another spreadsheet that does vlookups of the data based on the product number entered into cell B5. I need to copy-paste cell A2 from data sheet (Specs.xlsx) into the other workbook (Fact Sheet.xlsx) and print. Then copy/past A3 from data sheet to other workbook and print. Continue doing this for hundreds of rows and then stop if there is no data in the cell. Started a macro and it looks like this:

Windows("Specs.xlsx").Activate
Range("A2").Select
Selection.Copy
Windows("Fact Sheet.xlsx").Activate
Range("B5").Select
ActiveSheet.Paste
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True, _
IgnorePrintAreas:=False
Windows("Specs.xlsx").Activate
Range("A3").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Fact Sheet.xlsx").Activate
ActiveSheet.Paste
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True, _
IgnorePrintAreas:=False
End Sub

Any help is greatly appreciated.
Regards.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
There are a bunch of built-in shortcuts to do things like this.

For one row use this:

Code:
Range("A2").End(xlToRight).Select

To select all contiguous cells use this:

Code:
Range("A2").CurrentRegion.Select
 
Upvote 0
Stephen,

Welcome to the Board!

You might consider the following...

Code:
Sub CopySpecs()
Dim i As Long
Dim wb1 As Workbook, wb2 As Workbook
Set wb1 = Workbooks("Specs.xlsx")
Set wb2 = Workbooks("Fact Sheet.xlsx")
i = 2

Do
    wb2.Sheets(1).Range("B5").Value = _
        wb1.Sheets(1).Range("A" & i)
    wb2.Sheets(1).PrintOut Copies:=2, Collate:=True, _
        IgnorePrintAreas:=False
    i = i + 1
Loop Until wb1.Sheets(1).Range("A" & i) = ""
End Sub

I strongly suggest you test on copies of your workbooks before proceeding. It might be that the macro runs more quickly than your printer can handle, so you may receive print buffer errors or just find that some pages aren't printed. If that's the case we may need to add some variation of DoEvents or allow for an occasional pause.

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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