Help to modify code Worksheet_Change(ByVal Target As Range) to ByVal Target As Object

SSF1590

Board Regular
Joined
Oct 20, 2019
Messages
73
Hello,

I have this code that filters data by the selection in cell 8 (data variation). Can I please have your help to modify ByVal Target As Range to ByVal Target As Object so it filters by the selection made in combobox1?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$8" Then
    If Range("C8").Formula = "All" Then
        Range("A13").AutoFilter
    Else
        Range("A13").AutoFilter Field:=13, Criteria1:=Range("C8")
    End If
End If
End Sub
 
Last edited by a moderator:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I am sorry for my lack of knowledge in VBA. I pretty much have basic knowledge. Can you please explain me how?
I actually tried to place the value of the combobox in a cell but by using a formula. VBA does not read it of course, so I am kind of lost.
 
Upvote 0
If its a Form Control combo on the sheet, then right click > Format Control > Control and enter the info there.
 
Upvote 0
Sorry I think I got you wrong. You mean to use data validation instead of a combobox and leave the code as it is. The current code I have work with the value on cell 8 using data validation.
 
Upvote 0
Now I am confused. If it's working with Data Validation, why change it to Combobox1?
 
Last edited:
Upvote 0
Yes, it is working with data validation. The reason k would like to change is because with data validation you don’t know you have a drop down list until you click on the cell. With a ComboBox it’s pretty clear.
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,337
Members
453,032
Latest member
Pauh

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