Making different ranges appear to fill out according to the number of changes selected

AndrwT

New Member
Joined
Mar 30, 2016
Messages
29
Hi all, good afternoon!

Had a look in the search bar, however didn't find any thread similar to what I'm looking for.

Basically; I have the following:

ABCDEFG
1Change reason?Dropdown
2Nb of Changes?Dropdown
(max 5)
3NameNameNameNameName
4SurnameSurnameSurnameSurnameSurname
5DateDateDateDateDate
6IDIDIDIDID
7ValueValueValueValueValue

<tbody>
</tbody>

What I need is, when selecting in B2 the number of changes required, the respective ranges in columns C to G appear so that the user can fill out the information.

This is also depending on the reason dropdown list in B1, if scneario 1, the ranges will show fields to fill according to the reason; those fields will change if another reason is selected (all the data is stored in another tab in the same workbook).

So, if I select 3 changes with scenario 1, I would like ranges C3:C7; D3:D7 and E3:E7 to appear to be filled out with the required cells for scenario 1, and I would like ranges F3:F7 and G3:G7 to show nothing and stay blank.
If selecting 1 change, only range C3:C7; and if 5, all ranges show fields to be filled.

I know there is a code to do this, however I haven't got the enough knowledge to create it.

PS: my priority is to learn the code to make the ranges appear or not.

Thank you all for your help!!

Andrew
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
This worksheet event code should be copied to the worksheet code module of the sheet where your dropdown box resides.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
    If Target.Address = "$B$2" And Target <> "" Then
        Columns("C:G").Hidden = True
        On Error Resume Next
        Range("C1").Resize(1, Target.Value).EntireColumn.Hidden = False
        On Error GoTo 0
    End If
Application.EnableEvents = True
End Sub
Once installed, the code will execute only if there is a change in cell B2 values. It will make no changes to the applicable columns if cell B2 is rendered blank.
 
Upvote 0
Hi JLGWhiz;

Thank you for your reply!

Sorry to answer so late, I was out for several days and have only been able to catch up now.

Will try in the days to come and let you know if it works :)

Thanks!

Andrew


This worksheet event code should be copied to the worksheet code module of the sheet where your dropdown box resides.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
    If Target.Address = "$B$2" And Target <> "" Then
        Columns("C:G").Hidden = True
        On Error Resume Next
        Range("C1").Resize(1, Target.Value).EntireColumn.Hidden = False
        On Error GoTo 0
    End If
Application.EnableEvents = True
End Sub
Once installed, the code will execute only if there is a change in cell B2 values. It will make no changes to the applicable columns if cell B2 is rendered blank.
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,674
Members
449,179
Latest member
fcarfagna

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