![]() |
Object Required error
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. |
Object Required error
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 -- Cheers, Ryan "Gary McCarthy" wrote: 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. |
All times are GMT +1. The time now is 10:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com