Hi Guys,
I have a macro that inserts rows in a workbook and is applied to all worksheets, this works great but I am trying to modify it to only work on the open worksheet (i am supposing this is activesheet) but it keeps failing.
The code that is working on all the sheets is as follows
My modified code for active sheet is as follows but I keep getting an error
'Run-time error '424':
Object required
I have highlighted the error that is shown in red below
If someone can advise where I am going wrong it would be very much appreciated
Thanks
Andy
I have a macro that inserts rows in a workbook and is applied to all worksheets, this works great but I am trying to modify it to only work on the open worksheet (i am supposing this is activesheet) but it keeps failing.
The code that is working on all the sheets is as follows
Code:
Sub InsertRows()Dim ws As Worksheet
Dim found As Long
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Search" Then ' "Search" (this is excel name but can be changed by user and break code
ws.Activate
found = ws.Columns(2).Find(What:="*", After:=ws.Cells(1, 2), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row
If found < 22 Then ws.Rows(found & ":" & found + (21 - found)).Insert
End If
Next ws
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
My modified code for active sheet is as follows but I keep getting an error
'Run-time error '424':
Object required
I have highlighted the error that is shown in red below
Code:
Sub InsertRows_Activesheet()
Dim found As Long
With ActiveSheet
[COLOR=#ff0000]found = .Columns(2).Find(What:="*", After:=ws.Cells(1, 2), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row[/COLOR]
If found < 22 Then ws.Rows(found & ":" & found + (21 - found)).Insert
End With
MsgBox "Done!"
End Sub
If someone can advise where I am going wrong it would be very much appreciated
Thanks
Andy