Delete Rows From ActiveSheet based on listbox selections

gizmoware

New Member
Joined
Jul 6, 2011
Messages
3
Hello,
I am a beginner on this forum so feel free to let me know if i am showing any code incorrectly.

So here is my issue. I have a sheet containing rows of different components to a system with different designations (ex. FW-TAT-1). I have another sheet that i use to pull these designations into 6 separate listboxs in a userform. When I click my command button i copy the masterlist to a new sheet and name it through TextBox2. What then happens is the rows that do not contain the correct designation (based on the selection in the listboxs) in column "C" of the new sheet are deleted. This works perfectly for one listbox.

Private Sub CommandButton2_Click()

'This copies the Masterlist
Worksheets("Air Handling Unit").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = TextBox2
Range("C1") = TextBox2

'This is where my problem lies
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Firstrow = ActiveSheet.UsedRange.Cells(1).Row + 5
Lastrow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
For Lrow = Lastrow To Firstrow Step -1
If ActiveSheet.Range("C" & Lrow).Value <> ListBox1.Value Then ActiveSheet.Range("C" & Lrow).EntireRow.Delete
If ActiveSheet.Range("C" & Lrow).Value <> ListBox2.Value Then ActiveSheet.Range("C" & Lrow).EntireRow.Delete
If ActiveSheet.Range("C" & Lrow).Value <> ListBox3.Value Then ActiveSheet.Range("C" & Lrow).EntireRow.Delete
If ActiveSheet.Range("C" & Lrow).Value <> ListBox4.Value Then ActiveSheet.Range("C" & Lrow).EntireRow.Delete
If ActiveSheet.Range("C" & Lrow).Value <> ListBox5.Value Then ActiveSheet.Range("C" & Lrow).EntireRow.Delete
If ActiveSheet.Range("C" & Lrow).Value <> ListBox6.Value Then ActiveSheet.Range("C" & Lrow).EntireRow.Delete
End Sub
What is happening is every row is being deleted off of the new sheet. I want the selections in the listboxs to still show up. These are not multiselect listboxs.

Thanks for the help
logan
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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