View Code two routines won't run together - what do I need to do

rintelen

Board Regular
Joined
Jul 30, 2006
Messages
96
Hi everyone

I have this new piece of code I wish to add to a tab called the PV Calculator.

Sub worksheet_selectionChange(ByVal target As Range)
If Range("GB12").Value = 1 Then Rows(9).EntireRow.Hidden = True
If Range("GB12").Value = 0 Then Rows(9).EntireRow.Hidden = False
End Sub

However, when I go to do View Code there is a macro already there that looks like this:

Private Sub worksheet_selectionChange(ByVal target As Excel.Range)
With target
If .Count > 1 Then Exit Sub
If .Address(False, False) = "C17" Then _
Range("C18").ClearContents
If .Address(False, False) = "17" Then _
Range("C7").ClearContents
End With
End Sub

If I just paste one under the other then the above doesn't work, nor does the top one.

I'm not very clever at this so I need assistance. How do I associate these separately with the tab called PV calculator.

Secondly I need the top one to update the moment the person enters the tab (not waiting until somethign is clicked on the screen).

Any help would be much appreciated.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try changing the top one to

Code:
Private Sub Worksheet_Activate()
Rows(9).Hidden = Range("GB12").Value = 1
End Sub
 
Upvote 0
Well maybe I'm doing something wrong. Where do I put this? I use excel 2010. If I put the top one (or yours) above the other one neither of them work. (I'm looking at the View Code of the tab called PV calculator)

Will it work if the tab is protected?
 
Upvote 0
It sounds like the code is in the right place.

If the sheet is protected then you will need to unprotect it in the code

Code:
Private Sub Worksheet_Activate()
Me.Unprotect Password:="abc"
Rows(9).Hidden = Range("GB12").Value = 1
Me.Protect Password:="abc"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,314
Members
452,905
Latest member
deadwings

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