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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

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