Delete Rows Based on Drop-Down

Edavis1999

New Member
Joined
Aug 23, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi guys!

I've made this so that when people toggle the drop-down in B5 it populates either "Item" based on No and Items 1-6 based on Yes. What I want to be able to do is have the A8-A12 and so on - collapse when someone replies No rather than having blank fields.

Is this something I will need a macro for, and if so, can someone help me through it?

Ty~~

1661258751720.png
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). Also, use code tags to post the code you are currently using to populate either "Item" based on No and Items 1-6 based on Yes.
 
Upvote 0
It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). Also, use code tags to post the code you are currently using to populate either "Item" based on No and Items 1-6 based on Yes.
Wow, this is a fantastic add-on!

Interactive expense form.xlsm
ABC
1Expenses form
2Name:
3Date: 23/08/2022
4Are you making more than one claim?
5Select Yes or NoYes
6Has prior consent been granted and by who?
7Item 1--
8Item 2
9Item 3
10Item 4
11Item 5
12Item 6
13Type of expense (meal, drinks, travel, hotel etc.):
14Item 1
15Item 2
16Item 3
17Item 4
18Item 5
19Item 6
20Reason for event:
21Item 1
22Item 2
23Item 3
24Item 4
25Item 5
26Item 6
27Evidence (physical receipt, digital receipt, bank statement etc.):
28Item 1
29Item 2
30Item 3
31Item 4
32Item 5
33Item 6
34Cost of each item (£)
35Item 1
36Item 2
37Item 3
38Item 4
39Item 5
40Item 6
41Amount Claimed:£0.00
Sheet2
Cell Formulas
RangeFormula
B3B3=TODAY()
A7:A12A7=IFERROR(INDIRECT("List"&B5),"")
A14:A19A14=IFERROR(INDIRECT("List"&B5),"")
A21:A26A21=IFERROR(INDIRECT("List"&B5),"")
A28:A33A28=IFERROR(INDIRECT("List"&B5),"")
A35:A40A35=IFERROR(INDIRECT("List"&B5),"")
B41B41=SUM(B35:B40)
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
B5List=Listt
B7:B12ListYes,No
B28:B33ListPhysical reciept,Digital reciept,Bank stament,Copy of reciept
C7List--,ADC,JXD
B14ListOther,Hotel,Train,Flight,Taxi,Meal,Drinks,Covid Test,Subscription
B15:B19ListHotel,Train,Flight,Taxi,Meal,Drinks,Covid Test,Subscription
B21ListOther,Arbitration,Client Meeting,Court,Business Development
B22:B26ListArbitration,Client Meeting,Court,Business Development
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection of "Yes" or "No" in B5.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Address(0, 0) <> "B5" Then Exit Sub
    Application.ScreenUpdating = False
    Dim x As Long, y As Long, lRow As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row - 1
    Select Case Target.Value
        Case "No"
            For x = 7 To lRow Step 7
                Range("A" & x) = "Item"
                Range("A" & x + 1).Resize(5).ClearContents
                Rows(x + 1 & ":" & x + 5).Hidden = True
            Next x
        Case "Yes"
            For x = 7 To lRow Step 7
                Rows(x + 1 & ":" & x + 5).Hidden = False
                For y = 0 To 5
                    Range("A" & x + y) = "Item " & y + 1
                Next y
            Next x
    End Select
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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