error in code

cprince

Board Regular
Joined
Jul 4, 2006
Messages
67
Hi All,

I keep getting a application-object defined error.on this line

Set LastR = .Range("A65500").End(x1up).Select

Can someone tell me what im doing wrong?

Code:
Public Sub CommandButton1_Click()
Dim ws As Worksheet
Dim LastR As Range



'clears the worksheet
    Sheets("All Sheets").Select
    Cells.Select
    Selection.Interior.ColorIndex = xlNone
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Selection.Delete Shift:=xlUp
    Range("A1").Select
    Rows("1:1").RowHeight = 72

'grabs all the data from the worksheet and puts it in the "allsheets" tab

For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> "All Sheets" Then
        With Sheets("All Sheets")
        Set LastR = .Range("A65500").End(x1up).Select
        End With
        ActiveCell.Offset(1, 0).Range("A1").Select
        If IsEmpty(Range("A1")) Then Set LastR = Range("A1")
        
        
        ws.Range("A1:AM3000").Copy LastR
    End If
Next
    Selection.End(xlUp).Select
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Hi
get rid of Select and typo

Set LastR = .Range("A65500").End(xlUp)

Code:
Public Sub CommandButton1_Click()
Dim ws As Worksheet
Dim LastR As Range



'clears the worksheet
    With Sheets("All Sheets")
         .Cells.Delete
         .Rows("1:1").RowHeight = 72
    End With
'grabs all the data from the worksheet and puts it in the "allsheets" tab

For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> "All Sheets" Then

        With Sheets("All Sheets")
              Set LastR = .Range("A" & Rows.Count).End(xlUp).Offset(1)

              If IsEmpty(.Range("A1")) Then Set LastR = .Range("A1")
        End With
          
        ws.Range("A1:AM3000").Copy LastR
    End If
Next
End Sub
 

cprince

Board Regular
Joined
Jul 4, 2006
Messages
67
Thanks very much,

But in the code u sent me, Don't I still need to offset the cell one down for each sheet, Otherwise it will past over the last row?
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Thanks very much,

But in the code u sent me, Don't I still need to offset the cell one down for each sheet, Otherwise it will past over the last row?

Have you tried the code?
 

cprince

Board Regular
Joined
Jul 4, 2006
Messages
67
Yup,

Works great. I just added the offset at the end

Set LastR = Sheets("All Sheets").Range("A" & Rows.count).End(xlUp).Offset(1)

and now that works fine, Thanks Jindon.
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Yup,

Works great. I just added the offset at the end

Set LastR = Sheets("All Sheets").Range("A" & Rows.count).End(xlUp).Offset(1)

and now that works fine, Thanks Jindon.

try the entire code that I have posted.
 

Forum statistics

Threads
1,141,681
Messages
5,707,796
Members
421,529
Latest member
Balintn

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
Top