Object Required error


G

Gary McCarthy

I have the below code that has been working fine and still does in some
macros, however in others it has stopped and returns the 424 Object Required
error -

Dim ws As Worksheet
Dim wsName As String
Set ws = ActiveSheet
ws.Move After:=Sheets(Sheets.Count)

lastrow = Worksheets(ws.Name).Cells(Rows.Count, "A").End(xlUp).Row

Range("H2").AutoFill Range("H2:H" & lastrow)


Why would this be happening all of a sudden and only in certain macros?

Thanks.
 
Ad

Advertisements

R

Ryan H

Since you didn't indicate which line of code is giving you the error, we are
left to guess. Maybe it is this line:

lastrow = Worksheets(ws.Name).Cells(Rows.Count, "A").End(xlUp).Row

You actually don't have to use Worksheets(ws.Name) because you have already
set the object variable (ws) to the ActiveSheet. You could just use:

lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row

Try this code. I took the liberty of shortening it for you. If it throws
an error, indicate to us where the error is occuring. Hope this helps! If
so, let me know, click "YES" below.

Dim LastRow As Long

With ActiveSheet
.Move After:=Sheets(Sheets.Count)

LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

.Range("H2").AutoFill .Range("H2:H" & LastRow)
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top