Most of the time, Excel users manually copy (CTRL+C) cell values and then paste (CTRL+V) them into other cells. Excel VBA copy cell value to the clipboard, makes this type of copying and pasting more convenient. Copying a specific worksheet or active worksheet’s cell value, using “MSForms DataObject Library“, as well as enabling select to auto copy are the discussed methods in this article. Let’s say we have a certain date’s total sales amount (i.e., E14 cell) and we want to copy the cell value to the clipboard for further pasting.
In this article we demonstrate the prerequisites and multiple macro variants for Excel VBA copy cell value to the clipboard.
Download Excel Workbook
4 Easy Ways to Copy Cell Value to Clipboard in Excel VBA
Excel macros require Module insertion prior to their execution. Follow the below instructions to be able to insert a Module:
➤ Press ALT+F11 simultaneously to open the Microsoft Visual Basic window.
➤ Go to Insert > Module. Afterwards, Excel opens a VBA Module where users can insert their macros.
Go through the latter section to find out the appropriate macro variants suitable for your case.
Method 1: Copying a Specific Worksheet’s Cell Value to Clipboard in Excel VBA
Sometimes, users have multiple Excel Worksheets within a Workbook. In that case, this macro variant is useful to copy any assigned cell values to the clipboard for later usage.
Step 1: Type the following macro in the inserted Module.
Sub Copy_SWS_CellValue_Clipboard()
Worksheets("5 Aug").Range("E14").Copy
End Sub
Macro Explanation
- VBA “Range” property takes the specific worksheet and cell value references, and after that the “.Copy” method copies it to the clipboard.
Step 2: After inserting the macro into the module, use the F5 key or go to Run > Run Macro F5 to execute it.
Read More: [Solved:] There Is a Problem with Clipboard in Excel
Method 2: Excel VBA to Copy Cell Value from Active Sheet to Clipboard
As an alternative to Method 1, Excel Macros can copy an activesheet’s specific cell value and store it for further usage.
Step 1: Type the below macro in the module.
Sub Copy_AWS_CellValue_Clipboard()
ActiveSheet.Range("E14").Copy
End Sub
Macro Explanation
- VBA ActiveSheet.Range().Copy offers users to provide any cell copy to clipboard after its execution.
Step 2: Hit F5 or repeat Step 2 of Method 1 to execute the macro.
Method 3: Enabling Auto Copy Cell Values to Clipboard Cell in Excel VBA
What if users want to auto copy to the clipboard after selecting or highlighting a cell within a range? The VBA Intersect method secures the selection to be within a range.
Step 1: Paste the following macro into a Sheet’s Code window (Double Click on any Sheet to display the sheet code window).
Private Sub Worksheet_SelectionChange(ByVal cTarget As Range)
If Not Intersect(cTarget, Range("B4:E14")) Is Nothing Then
cTarget.Copy
End If
End Sub
Macro Explanation
- VBA Intersect method returns a range upon the assigned Arg’s intersection.
- VBA IF function implements a condition and performs “.Copy” after its affirmation.
Step 2: Now, return to the specific worksheet. And Excel automatically executes the macro.
Read More: Excel VBA: Copy Range to Clipboard (7 Suitable Examples)
Method 4: Using Microsoft Forms Object Library to Send Cell Value to Clipboard
Users can use the Microsoft Forms Object Library to enable “Data Objects” in macros. However, they need to add the Microsoft Forms 2.0 Object Library from References first.
Activating Microsoft Forms 2.0 Object Library
To activate the Microsoft Forms Object Library, follow the below steps.
➤ Move to Tools > Reference.
➤ Find the Microsoft Forms 2.0 Object Library within the Available References. After being unable to find it, click on Browse.
➤ Clicking Browse takes you to Windows > System32. Then select FM20.DLL and click Open.
➤ Excel activates the Microsoft Forms 2.0 Object Library, as shown in the latter image. Click OK.
Step 1: Type the below macro in the module.
Sub Send_CellValue_Clipboard()
Dim CellValue As MSForms.DataObject
Set CellValue = New MSForms.DataObject
CellValue.SetText ActiveSheet.Range("E14")
CellValue.PutInClipboard
End Sub
Macro Explanation
- The CellValue variable is assigned as DataObject and gets set to a new MSForms.DataObject.
- Range() VBA Worksheets.Range provides a specific cell value.
- .PutInClipboard sends the cell value to clipboard.
Step 2: Run the macro.
Read More: How to Copy Text to Clipboard Using VBA in Excel (2 Easy Ways)
Verification of the Macros’ Outputs
We constitute all the macro variants by assuming different situations. After running or executing (pressing F5) a macro, users may want or need to confirm or paste the copied cell value into another cell.
Say we need to paste the Daily Sales (i.e., 5 Aug) into another Excel Worksheet (i.e., Sales Report) or anywhere.
🔼 So, you execute any of the macros, then return to the active worksheet or the 5 Aug worksheet. You’ll be seeing Excel copies the E14 cell or current selection (in Method 3).
🔼 Also, you can see the value getting saved in the Clipboard (Home > Click Clipboard Icon).
🔼 Paste (CTRL+V) the value in the Sales Report worksheet as desired. You see, the value gets pasted. So, it’s obvious to say that those macros really copy the assigned cell value to the clipboard as they are supposed to.
Read More: How to Paste From Clipboard to Excel Using VBA
⧭ Things to Keep in Mind
The offered macros only copy the cell values. Cell containing formula results in #REF error in the case of Methods 1, 2 and 3. So, make sure the cell only contains values. Otherwise, users need to paste the values as Paste as Value & Number Formatting.
Conclusion
This article demonstrates multiple variants of VBA Macros to cell value to the clipboard. Go through the Macro Explanations for a better understanding. Use any of the methods to accomplish your goal. Comment if you have further inquiries or have anything to add. Moreover, do check out our awesome website, ExcelDemy, to find interesting articles on Excel.