LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default VB macros issue with selecting cells on different page

I think the problem is with trying to select a range on another sheet via a
commandbutton (which is an ActiveX control). Seems it would work with a
button from the forms toolbar. I can't explain the technical details, but
you can fix it by not selecting anything (which is unnecessary, slows down
your code, and can make it harder to read).

With Sheets("sheet2")
.Range(.Cells(1, 1), .Cells(10, 10)).Copy
End With
Sheets("Sheet1").Range("A1").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False



"Sunny" wrote:

On "Sheet1" I have a command button to:
1) copy a range of cells on "Sheet2"
2) paste copied values back into "Sheet1"

The following set of instructions seem to work.

Private Sub CommandButton1_Click()
Sheets("sheet2").Select
Sheets("Sheet2").Range("A1:J10").Select
Selection.Copy
Sheets("Sheet1").Select
Sheets("Sheet1").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

End Sub

The instructions below doesn't work.

Private Sub CommandButton1_Click()
Sheets("sheet2").Select
Sheets("Sheet2").Range(Cells(1, 1), Cells(10, 10)).Select 'offending line
Selection.Copy
Sheets("Sheet1").Select
Sheets("Sheet1").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

End Sub

The offending line is the third line with ".Range(...)" in it. The second
method seems to work if I copy/paste cells from the same sheet.

I would like to use numeric values to set the range because the table of
values that I want to copy on "Sheet2" will change.

 
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
Running Macros by selecting from a dropdown list FionaR Excel Discussion (Misc queries) 3 January 3rd 07 01:24 PM
selecting 2 ranges, 1 Worksheet, printing on 1 page PDF need help please Excel Discussion (Misc queries) 0 October 17th 06 09:03 PM
By selecting cells adjacent to cells tally sheet tom Excel Worksheet Functions 2 September 20th 06 07:09 PM
selecting different cell ranges across sheets, to display on summary page NetMax Excel Discussion (Misc queries) 4 January 17th 06 07:42 PM
macros on one page frendabrenda1 Excel Discussion (Misc queries) 1 October 24th 05 12:18 PM


All times are GMT +1. The time now is 12:43 AM.

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

About Us

"It's about Microsoft Excel"