Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time 1004 error on range select


Hello,

I have a command button on Sheet1 that I use to insert a new column o
that sheet, but now need it to also copy column "A" on Sheet2 to th
first blank column on that sheet.

Here is what I have:

Private Sub CommandButton2_Click()

' Insert new column on Sheet1
ActiveCell.Select
Selection.EntireColumn.Insert Shift:=xlToRight

Dim src As Range
Dim dest As Range
Set src = Cells("2", ActiveCell.Column + 1)
Set dest = Cells("2", ActiveCell.Column)
src.Copy dest

' copy column on Sheet2
Sheets("sheet2").Activate
Columns("A").Select
Selection.Copy

Range("E1").End(xlToRight).Select
Selection.EntireColumn.Select
ActiveSheet.Paste
End Sub

But, it seems like no matter how I phrase the range select on Sheet2,
get a run-time 1004 error: select method of range class failed. I'v
also tried:

' copy column on Sheet2
Sheets("sheet2").Activate
Range("A1").Select
Selection.Copy

but still get the same error.

Any suggestions would be appreciated.

Thank you

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time 1004 error on range select


Morgan

Your code appears work ok on my Excel 97

I do suggest some changes

change

' copy column on Sheet2
Sheets("sheet2").Activate
Columns("A").Select
Selection.Copy


to

Sheets("sheet2").Columns("A").Copy ' no need to activate sheet o
column



Change

Range("E1").End(xlToRight).Select
Selection.EntireColumn.Select
ActiveSheet.Paste


to

dim DestCol as Integer
DestCol = Range("E1").End(xlToRight).Column
Sheet("sheet1").Columns(DestCol).Paste
Selection.EntireColumn.Selec

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Run-time 1004 error on range select

Morgan

If you are using XL97 and the command button from the Control Toolbox, make
sure you set the TakeFocusOnClick property of the command button to False.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Morgan" wrote in message
...

Hello,

I have a command button on Sheet1 that I use to insert a new column on
that sheet, but now need it to also copy column "A" on Sheet2 to the
first blank column on that sheet.

Here is what I have:

Private Sub CommandButton2_Click()

' Insert new column on Sheet1
ActiveCell.Select
Selection.EntireColumn.Insert Shift:=xlToRight

Dim src As Range
Dim dest As Range
Set src = Cells("2", ActiveCell.Column + 1)
Set dest = Cells("2", ActiveCell.Column)
src.Copy dest

' copy column on Sheet2
Sheets("sheet2").Activate
Columns("A").Select
Selection.Copy

Range("E1").End(xlToRight).Select
Selection.EntireColumn.Select
ActiveSheet.Paste
End Sub

But, it seems like no matter how I phrase the range select on Sheet2, I
get a run-time 1004 error: select method of range class failed. I've
also tried:

' copy column on Sheet2
Sheets("sheet2").Activate
Range("A1").Select
Selection.Copy

but still get the same error.

Any suggestions would be appreciated.

Thank you.


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time 1004 error on range select


Thank you. I'll go ahead and try out your suggestions right away.

I did notice something that I forgot before. Column A that I a
pasting from has conditional formating, with absolute references t
$A$1. When I paste this column, the conditional formating gets pasted
too.

When I replace...

ActiveSheet.Paste

With...

ActiveSheet.PasteSpecial Paste:=xlFormulas

I get another run-time 1004 error: Application-defined o
object-defined error.

Thanks again

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

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
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 10 April 16th 09 09:06 PM
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 3 April 14th 09 10:35 PM
Run-Time error '1004' : Select method of Range class failed [email protected] Excel Discussion (Misc queries) 3 March 9th 07 01:36 PM
Run-time error "1004" Select method of range class failed Tallan Excel Discussion (Misc queries) 3 March 7th 07 05:22 PM
error 1004 Select method of Range class failed J.E. McGimpsey Excel Programming 1 September 12th 03 07:42 PM


All times are GMT +1. The time now is 01:03 AM.

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"