Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
HrvojeZagi
 
Posts: n/a
Default Copy paste to another sheet

Hi,

I would like to copy, paste data from one sheet to another sheet.
I have made command button with this code, and it doesn't work. If someone
can help?

Range("A4:C4").Select
Selection.Copy
Sheets("Data").Select
Range("A2").Select ' code stops on this sentence (even if I put range
A2:C2)
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

Thanks in advance


  #2   Report Post  
Dave O
 
Posts: n/a
Default

Create a command button from the Forms toolbar rather than the Controls
Toolbox toolbar, and assign your macro to it.

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

My bet is you used a commandbutton from the control toolbox toolbar as your
button.

If you did, then this code is behind the worksheet.

Unqualified range references in a General module refer to the activesheet. But
when the code is behind the worksheet, this unqualified range refers to the
sheet that owns the code.

And when you do "Range("a2").select", xl thinks you mean the sheet that owns the
code--not the DATA sheet. And you can't select a cell on a sheet that isn't
active.

You could drop the .selects and use something like:

Option Explicit
Private Sub CommandButton2_Click()
Me.Range("A4:C4").Copy
Sheets("data").Range("A2").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

In fact, since you're pasting values, you can just assign the values, too:

Option Explicit
Private Sub CommandButton1_Click()
Dim rngToCopy As Range
Set rngToCopy = Me.Range("A4:C4")
With rngToCopy
Worksheets("data").Range("a2") _
.Resize(.Rows.Count, .Columns.Count).Value _
= rngToCopy.Value
End With
End Sub

HrvojeZagi wrote:

Hi,

I would like to copy, paste data from one sheet to another sheet.
I have made command button with this code, and it doesn't work. If someone
can help?

Range("A4:C4").Select
Selection.Copy
Sheets("Data").Select
Range("A2").Select ' code stops on this sentence (even if I put range
A2:C2)
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

Thanks in advance


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't Copy and Paste between Excel 2003 Workbooks wllee Excel Discussion (Misc queries) 6 March 30th 05 02:59 PM
macro to copy columns to sheet Es Excel Discussion (Misc queries) 1 March 7th 05 02:03 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. RonMc5 Excel Discussion (Misc queries) 9 February 3rd 05 12:51 AM
I get wrong dates when i paste from a different sheet into a new s mmollat Excel Discussion (Misc queries) 2 January 6th 05 07:35 PM
vba to sort group copy paste to another sheet mango Excel Worksheet Functions 0 November 5th 04 04:27 AM


All times are GMT +1. The time now is 04:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"