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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

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