.Select gives Runtime Error 1004 - Select Method of Worksheet Class Failed, or .Copy removes Data

Rhodess

New Member
Joined
Feb 24, 2013
Messages
11
I'm havin a problem with the following macro, which works standalone, but not when assigned to a button:
Code:
Private Sub CommandButton1_Click()
'Combine Columns
'This macro will clear the contents of column A in "Final", then
'copy the values from "Misc" column A to "Final" column A, and then
'append the values in "Output" column A to the bottom of that list in "Final" column A
Worksheets("Final").Select 'The sheet where you want the results
Range("A:A").ClearContents
Worksheets("Misc").Select 'The sheet where first column data is
[COLOR=#ff0000]Range("A1:" & Range("A65536").End(xlUp).Address).Select[/COLOR]
Selection.Copy
Worksheets("Final").Select 'Go back to paste the data
Range("A1").Select
ActiveSheet.Paste
Worksheets("Output").Select 'the sheet where second column data is
Range("A1:" & Range("A65536").End(xlUp).Address).Select
Selection.Copy
Worksheets("Final").Select 'go back to paste the data
Range("A65536").End(xlUp).Select
Selection.Offset(1, 0).Select
ActiveSheet.Paste
Range("A1").Select
Columns("A:A").ColumnWidth = 27
End Sub
I immediately get the 1004 run-time error. If I change .Select to .Copy and remove the Selection.Copy below, it appears to work since I see the data flash up, then dissappear and it stops on cell A1

Can someone please take a look and see where I'm messing up?

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this...

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] CommandButton1_Click()
    [color=green]'Combine Columns[/color]
    [color=green]'This macro will clear the contents of column A in "Final", then[/color]
    [color=green]'copy the values from "Misc" column A to "Final" column A, and then[/color]
    [color=green]'append the values in "Output" column A to the bottom of that list in "Final" column A[/color]
    Application.ScreenUpdating = [color=darkblue]False[/color]
    Worksheets("Final").Range("A:A").ClearContents    [color=green]'The sheet where you want the results[/color]
    [color=darkblue]With[/color] Worksheets("Misc")    [color=green]'The sheet where first column data is[/color]
        .Range("A1", .Range("A65536").End(xlUp)).Copy _
                Destination:=Worksheets("Final").Range("A1")    [color=green]'paste the data[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]With[/color] Worksheets("Output")    [color=green]'the sheet where second column data is[/color]
        .Range("A1", .Range("A65536").End(xlUp)).Copy _
                Destination:=Worksheets("Final").Range("A65536").End(xlUp).Offset(1)    [color=green]'paste the data[/color]
    [color=darkblue]End[/color] With
    Worksheets("Final").Select
    Columns("A:A").ColumnWidth = 27
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top