worksheet code to run on other sheet

Steeviee

Active Member
Joined
Sep 9, 2009
Messages
380
Hello.

I'm trying to run some code so that when a certain cell is clicked, you go to another sheet and it runs an advanced filter... I've even given up on this and tried an autofilter but no joy. It will not let me select a cell in the new sheet (because I am running code from 1st sheet?). When I run the advanced filter, I get no matches, even though I know they are there.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
If Target.Column = 18 Then
    If Target.Cells.Value = "Y" Then
        RR = Target.Row
Sheets(3).Range("a2").Value = Sheets(1).Cells(RR, 3)
Sheets(3).Range("h2").Value = ""
Sheets(3).Range("i2").Value = ""
Sheets(3).Range("m2").Value = ""
Sheets(3).Range("p2").Value = ""
Sheets(3).Range("n2").Value = "Y"
Sheets(3).Activate
 
Sheets(3).Range("A11:Q10000").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
        Rows("1:2"), Unique:=False
    End If
End If
End Sub

this gives me an empty table. If I then go into sheet 3 and run the advanced filter myself, I get the rows matching my criteria (in row 2).

Can anyone help?

I tried using autofilter but it filtered the original sheet so I tried
Code:
Sheets(3).Range("A11").AutoFilter Field:=1, Criteria1:=Sheets(1).Cells(RR, 3)
but this doesn't do anything. (recording gives 'Selection.Auto...' but I can't select any cells)

Thanks for your time.

Additional:
I started this with two different workbooks and the code opened what is now contained in sheet(3). I had the issue with advanced filtering not giving any results and so tried combining the sheets. Now that I have, I realise that line
Code:
Sheets(3).Range("a2").Value = Sheets(1).Cells(RR, 3)
doesn't work either.
I'm having a complete failure.
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Please ignore green bit. i accidentally moved sheet 3 and so moved it back - making it into sheet 2.

I can now autofilter OK. I would still like to know why I can't advanced filter though.

Cheers,
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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