Anybody spot the error in this code?

stevelake

Board Regular
Joined
Jun 6, 2007
Messages
102
Hi

The code below is supposed to run when the contents of A7 are changed. Unfortunately it stops at ... "Rows("5:1000").Select"

With the message...

Error 1004 "Select method of range class failed"

If l take out the line "If Target.Address = "$A$7" Then"
and assign the rest of the code to a button then the code runs well so l guess it must be an error in that line


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$A$7" Then
Sheets("Data Entry").Activate
Rows("5:1000").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=Sheets("Viewing").Range("A7").Value

ActiveSheet.UsedRange.Offset(1, 0).SpecialCells _
(xlCellTypeVisible).EntireRow.Copy Sheets("Viewing").Range("A42")

ActiveSheet.AutoFilterMode = False
Sheets("Data Entry").Select
Range("A6").Select

Sheets("Viewing").Select
Range("A42").Select


End If

End Sub

All help and advice is greatly appreciated

Thanks

Steve
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The line is trying to select rows from the original sheet after already activating the Data Entry sheet, you need to qualify that you want it to select rows from Data Entry:
Code:
Sheets("Data Entry").Rows("5:1000").Select

Hope that helps! :)
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,927
Members
449,094
Latest member
teemeren

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