How to write Worksheet Change macro with Two Events

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 :LOL:.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Perhaps
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address ="$C$4" Then
        Rem do one thing
    End If

    If Target.Address ="$C$3" Then
        Rem do another thing
    End If
End Sub
 
Upvote 0
Mike you are awesome!!! Seriously it worked with a little tweaking of my own code. That was a simple fix - wish my simple mind could have figured that out.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,037
Messages
6,128,442
Members
449,453
Latest member
jayeshw

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