Need macro code based on conditions?

shushilm

New Member
Joined
Oct 5, 2016
Messages
7
Hi Team,

Can any one help me with the Macro code for the below situation:

  • I have the data validation in B1,B2,B3 where the user will select.
  • I have a filter in row5 where I exclude blanks below row5. Example below after filter it will not show row 8 & 11 as its blank.
  • Supplier # and Address is pulled based on the condition in B1,B2,B3 from a different sheet in the excel.

What I Need - A Macro which will filter for non blanks every time any of the drop down is changed, so it shows the data based on the current filter condition. Example - I got the below data based on "New Jersey", "Electrical" and "Yes" in B1,B2,B3, if I change Preferred Supplier to "No", the Macro should run to and re filter based on the new condition.

Thank you in advance!!


RowsColumn AColumn B
1StateNew Jersey
2ScopeElectrical
3Preferred Supplier (Yes/No)Yes
4
5Supplier #Address
6ABC1xyz1
7ABC2xyz2
8
9ABC4xyz4
10ABC5xyz5
11
12ABC7xyz7

<tbody>
</tbody>
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
put this in the sheet object where the data is

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
Case Is = "$B$1", "$B$2", "$B$3"
Range("A5:B" & Range("B" & Rows.Count).End(xlUp).Row).AutoFilter Field:=2, Criteria1:="***"
End Select
End Sub
 
Upvote 0
Hi Barry,

Thank you so much for the code, it works perfect!!

Have a nice weekend,
Regards,
Shushil
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,589
Members
449,174
Latest member
chandan4057

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