Copy and place values into another sheet

nej12

New Member
Joined
Nov 10, 2018
Messages
23
Hello,
Does anyone think this is too clunky? The below is copying the value of J2 cell and placing the values on the Save sheet. It works but it's slow?


Code:
Private Sub CommandButton5_Click() 'Save ActiveX ButtonSheets("Save").Select
Application.Goto reference:="R1C1"
'Rows("1:1").Select
Selection.insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Sheets("Donuts").Select
Application.Goto reference:="R2C10"
Selection.Copy
Sheets("Save").Select
Application.Goto reference:="R1C1"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
        
        




End Sub

Thank you,
Nej
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
.
Cleaner and simpler :

Code:
Sub cpyPaste()
Sheet1.Range("J2").Copy
Sheet2.Range("A1").PasteSpecial xlPasteValues
End Sub
 
Upvote 0
Solution
I meant to ask, if I wanted to first insert a row prior to pasting special into A1, do you know if the order would go like this:

*Oh and J2 has a formula in it like this: =(D15) it shows the values of another cell with formulas joining text from various other cells that just pulls information together. What's weird is =D15 (in J2) works and =(D15) works. Sometimes I was getting a REF!# error message when it would paste into J2. But not all of the time. I did try the below and seems to be ok...


Code:
Sheets("Sheet2").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Sheet1.Range("J2").Copy
Sheet2.Range("A1").PasteSpecial xlPasteValues

Thank you
 
Last edited:
Upvote 0
.
Either your code or this :

Code:
Option Explicit


Sub cpyPaste()
    Sheets("Sheet2").Rows(1).Insert shift:=xlShiftDown
    Sheet1.Range("J2").Copy
    Sheet2.Range("A1").PasteSpecial xlPasteValues
End Sub
 
Upvote 0
Or as you are just copying a single cell then you can just use

Code:
Sub cpyPaste()
    Sheets("Sheet2").Rows(1).Insert shift:=xlShiftDown
    Sheet2.Range("A1").Value = Sheet1.Range("J2").Value
End Sub

Btw, is there a reason why you are using the sheetname for the insert but the codename for the copy/paste?
 
Upvote 0
Hi Mark858,

thank you yours works too!

When you say codename versus sheetname do you mean when editor shows it like Sheet1(Save) if my sheet was named Save?
For me I opened a new workbook and didn't rename the sheets.
 
Upvote 0
The codename is the name outside the brackets that doesn't change if the sheet is renamed normally and isn't affected by the sheets being moved like it's Index would.

The Sheetname is the name inside the brackets that is the name that appears on the Sheet tab.

Coders often prefer to use a sheets codename if the code is applying to the same workbook as it is harder for users to mess up the code by their changes.

The reason I asked is it is normal (more consistent) to only use one naming convention in a procedure.
 
Upvote 0
That makes sense. I'm really really new with this stuff, but I try real hard to understand things. Now, it's funny you'd brought this topic up, I found myself confused over what sheet was what a couple months ago and had to look it up on the web. Sticking to one or the other makes sense alot. :)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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