VBA Delete Rows based on drop down list selection

Ridofhate

New Member
Joined
May 5, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Dear community members,
I'm new to VBA and would like to try something in one of my excel files. I would like to have a worksheet that based on a drop down list selection only keeps the rows which are referring to this selection.

For Example:
If D4 "LOG" is selected all rows which not contain "LOG" in column "A" should be deleted.
In this case the rows 120 - 142 would have been deleted (if Range is starting from "A74").

Do you have a good idea for a code?

Thank you very much! :)

2021-05-05_08h53_23.png
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
With the following code i worked to delete the rows. Is there also a possibility, that the way of selection is changed to "contain"? Means that a cell in Column A can contain several functional area and when it contains something from the drop down list it won't be deleted.

Thank you very much!

VBA Code:
Sub Selection()
With Sheets("Budget")
    .Range("A8").CurrentRegion.AutoFilter Field:=1, Criteria1:="<>" & .Range("D4").Value
    .Range("A8").CurrentRegion.Offset(1).EntireRow.Delete
    .AutoFilterMode = False
End With
End Sub
 
Upvote 0
Trackback. Is there someone who can help regarding this "contain" question?
 
Upvote 0
How about
VBA Code:
Criteria1:="<>*" & .Range("D4").Value & "*"
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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