PC Review
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Crashes
Excel VB
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Crashes
Excel VB
![]() |
Excel VB |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I have the following code (copied from a macro) into VB as follows:
Private Sub CommandButton1_Click() Sheets("Sheet1").Select Range("B5 17").SelectSelection.Copy Sheets("Sheet3").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("K22").Select End Sub When I run this from a button I get the following message - Runtime error 1004 Select method of Range class failed. Can someone please help me with the proper syntax. Thanks Nigel |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Have you got sheets called Sheet1 and Sheet3?
cheers Simon "Nigel Forge" <NigelForge@discussions.microsoft.com> wrote in message news:0907257F-2007-478F-9ABA-099168362E0D@microsoft.com... >I have the following code (copied from a macro) into VB as follows: > > Private Sub CommandButton1_Click() > > Sheets("Sheet1").Select > > > Range("B5 17").Select> Selection.Copy > Sheets("Sheet3").Select > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, > SkipBlanks _ > :=False, Transpose:=False > Range("K22").Select > > > End Sub > > > When I run this from a button I get the following message - Runtime error > 1004 > Select method of Range class failed. > > Can someone please help me with the proper syntax. > > Thanks > > Nigel |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Hi Simon
Yes I do actually have those sheet names - however I have just solved the problem - I did not use the Activate command and that is what has been hanging my code up- it is now fixed. Thanks fro responding. Private Sub CommandButton1_Click() > >Worksheets("Sheet1").Activate > Activesheet.Range("B5 17").Select> Selection.Copy Worksheets("Sheet3").Activate Activesheet.Range("A1").Select > > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, > SkipBlanks _ > :=False, Transpose:=False > Range("K22").Select > > > End Sub "Simon Murphy" wrote: > Have you got sheets called Sheet1 and Sheet3? > cheers > Simon > "Nigel Forge" <NigelForge@discussions.microsoft.com> wrote in message > news:0907257F-2007-478F-9ABA-099168362E0D@microsoft.com... > >I have the following code (copied from a macro) into VB as follows: > > > > Private Sub CommandButton1_Click() > > > > Sheets("Sheet1").Select > > > > > > Range("B5 17").Select> > Selection.Copy > > Sheets("Sheet3").Select > > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, > > SkipBlanks _ > > :=False, Transpose:=False > > Range("K22").Select > > > > > > End Sub > > > > > > When I run this from a button I get the following message - Runtime error > > 1004 > > Select method of Range class failed. > > > > Can someone please help me with the proper syntax. > > > > Thanks > > > > Nigel > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 
17").Select
