Deleting row depending on the content of a cell

Oyens

New Member
Joined
Jul 12, 2011
Messages
2
Hi,

I tried to create a macro to help me deleting row depending on the content of a cell.

I have one workbook containing two sheets. In Sheet A, you select several fields by using a drop down menu. Depending of you selecting on cell D6 and D7, Sheet B will delete some rows.
For example:
If sheet A cell D6= "firm" instead of "human" then
in sheet B you look in colomn A for "birth" and delete the entire row then
in sheet B you look in colomn A for "married" and delete the entire row then go back to sheet A
if sheet A in cell D7 = "FIP" then
in sheet B you look in colomn A for "Qrap" and delete the entire row

but if sheet A in cell D6 = "human" instead of "firm" then
in sheet B you look in colomn A for "kvk" and delete the entire row then
in sheet B you look in colomn A for "unit" and delete the entire row then go back to sheet A.

Many thanks in advance.

BR, Oyens
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
Sub test()

Dim r As Long
Dim lrow as Long
Application.ScreenUpdating = False

lrow = Worksheets("Sheet B").Range("A" & Rows.Count).End(xlUp).Row
    For i = lrow To 2 Step -1

        If Worksheets("Sheet A").Range("D6").Value = "Firm" and Worksheets("Sheet B").Range("A" & i).Value = "birth" Then
            Worksheets("Sheet B").Rows(i).Delete
       ElseIf Worksheets("Sheet A").Range("D6").Value = "Firm" and Worksheets("Sheet B").Range("A" & i).Value = "married" Then
            Worksheets("Sheet B").Rows(i).Delete
      ElseIf Worksheets("Sheet A").Range("D6").Value = "Human" and Worksheets("Sheet B").Range("A" & i).Value = "kvk" Then
            Worksheets("Sheet B").Rows(i).Delete
       ElseIf Worksheets("Sheet A").Range("D6").Value = "Human" and  Worksheets("Sheet B").Range("A" & i).Value = "unit" Then
             Worksheets("Sheet B").Rows(i).Delete
      End If

    Next i

lrow = Worksheets("Sheet B").Range("A" & Rows.Count).End(xlUp).Row
    For i = lrow To 2 Step -1
      If Worksheets("Sheet A").Range("D7").Value = "Fip" and Worksheets("Sheet B").Range("A" & i).Value = "Qrap" Then
            Worksheets("Sheet B").Rows(i).Delete
      End If

Next i

Application.ScreenUpdating = True

End Sub


Try this
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

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