How to Begin Macro by copying selected cells, then paste those cells.

PartTimeExcel

New Member
Joined
Dec 9, 2020
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm trying to begin begin my macro by copying cells that have been preselected with by the mouse. My goal is to be able to paste those cells onto another worksheet as the first step of my macro. I've tried a number of variations, and this was my most recent one, but the variable "startrange" is empty:

Dim labinfo As Worksheet
Dim lab2p As Worksheet
Dim labprint As Workbook
Dim startrange As Range

Set labinfo = ThisWorkbook.Worksheets("Print Labels Data")
Set lab2p = ThisWorkbook.Worksheets("Print Labels")
Set labprint = Workbooks.Open("\\server2\aNAHVAC\DevShipping\FBA Labels\Barcodes\FBA Return Barcodes.xls")
Set startrange = Selection

labinfo.Range("c2") = startrange

Please advise what code would work to copy the cells are highlighted with the mouse, and then paste them onto another sheet.
Thanks!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Put Set startrange = Selection before opening the other workbook. When you open the other workbook, the Selection changes to the Active workbook.
 
Upvote 0
Thank you.

I changed it so that the "Set startrange" line is the first set action, but it still does not paste anything per this code.

Of note, after I attempt to run the marcro, when I go to paste, this is on the clip board "Set startrange = Selection".

Any other thoughts?
Thanks!
 
Upvote 0
VBA Code:
Sub Macro1()
    Dim labinfo As Worksheet
    Dim lab2p As Worksheet
    Dim labprint As Workbook
    Dim startrange As Range
    
    Set startrange = Selection
    
    Set labinfo = ThisWorkbook.Worksheets("Print Labels Data")
    Set lab2p = ThisWorkbook.Worksheets("Print Labels")
    
    startrange.Copy
    labinfo.Range("c2").PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    
    Set labprint = Workbooks.Open("\\server2\aNAHVAC\DevShipping\FBA Labels\Barcodes\FBA Return Barcodes.xls")
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,824
Messages
6,127,108
Members
449,359
Latest member
michael2

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