wanderingsole
New Member
- Joined
- Dec 11, 2013
- Messages
- 2
I have managed to create a working worksheet change macro but have since learned I can not have two such macros in one worksheet (Excel 2010). The worksheet will have budget data to include two types budget adjustments and budget enhancements. I want to have a cell that allows the user to show a limited number of columns based on their requests. Thus,
1) How many adjustments will you have? The number in that cell will essentially show only the amount of request columns specified in that cell and hide the remainder in that range.
2) How many enhancements will you have? The number in that cell will do the same for the enhancement range - showing only the right amount of requested enhancements columns hiding the remainder.
The code that works for the 1st question is:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$3" Then
Columns("J:W").Hidden = False
Range(Cells(1, Target.Value + 9), Cells(1, 24)).EntireColumn.Hidden = True
Range(Cells(1, 24), Cells(1, 25)).EntireColumn.Hidden = False
End If
End Sub
I have no idea how to make an event to do both questions. Here is what I think the enhancement (? #2) code should be:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$4" Then
Columns("J:W").Hidden = False
Range(Cells(1, Target.Value + 28), Cells(1, 33)).EntireColumn.Hidden = True
Range(Cells(1, 33), Cells(1, 34)).EntireColumn.Hidden = False
End If
End Sub
Can anyone help me. I am just dangerous enough to create said code but only understand half of it - sad I know. Thanks ahead of time .
1) How many adjustments will you have? The number in that cell will essentially show only the amount of request columns specified in that cell and hide the remainder in that range.
2) How many enhancements will you have? The number in that cell will do the same for the enhancement range - showing only the right amount of requested enhancements columns hiding the remainder.
The code that works for the 1st question is:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$3" Then
Columns("J:W").Hidden = False
Range(Cells(1, Target.Value + 9), Cells(1, 24)).EntireColumn.Hidden = True
Range(Cells(1, 24), Cells(1, 25)).EntireColumn.Hidden = False
End If
End Sub
I have no idea how to make an event to do both questions. Here is what I think the enhancement (? #2) code should be:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$4" Then
Columns("J:W").Hidden = False
Range(Cells(1, Target.Value + 28), Cells(1, 33)).EntireColumn.Hidden = True
Range(Cells(1, 33), Cells(1, 34)).EntireColumn.Hidden = False
End If
End Sub
Can anyone help me. I am just dangerous enough to create said code but only understand half of it - sad I know. Thanks ahead of time .