PC Review Forums Newsgroups Microsoft Excel Microsoft Excel Crashes Excel VB

Reply

Excel VB

 
Thread Tools Rate Thread
Old 11-04-2006, 09:52 PM   #1
=?Utf-8?B?TmlnZWwgRm9yZ2U=?=
Guest
 
Posts: n/a
Default Excel VB


I have the following code (copied from a macro) into VB as follows:

Private Sub CommandButton1_Click()

Sheets("Sheet1").Select


Range("B517").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
  Reply With Quote
Old 16-04-2006, 03:23 PM   #2
Simon Murphy
Guest
 
Posts: n/a
Default Re: Excel VB

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("B517").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



  Reply With Quote
Old 17-04-2006, 02:56 PM   #3
=?Utf-8?B?TmlnZWwgRm9yZ2U=?=
Guest
 
Posts: n/a
Default Re: Excel VB

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("B517").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("B517").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

>
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off