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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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
 
Upvote 0
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?
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,238
Members
448,555
Latest member
RobertJones1986

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