Getting code to run!

Colleen45

Active Member
Joined
Jul 22, 2007
Messages
495
I have a problem getting this code to work

When ever one of the two names are selected the macro is supposed to run

code
Private Sub Worksheet_Change1(ByVal Target As Range)
If Target.Address(False, False) = "H6" Then
Select Case Target.Value
Case "Camps Bay", "Tokai": Call unhide_rows
End Select
End If
End Sub
/code
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Remove the 1 in:

Rich (BB code):
Private Sub Worksheet_Change1(ByVal Target As Range)

You can only have one Worksheet_Change event procedure and you certainly can't create more by changing the declaration.
 
Upvote 0
Remove the 1 in:

Rich (BB code):
Private Sub Worksheet_Change1(ByVal Target As Range)

You can only have one Worksheet_Change event procedure and you certainly can't create more by changing the declaration.

thanks Andrew,
I have already have code under procedure, and when i ran the code, it gave me ambiguous name errors.
if this is the code, that i have now, how would I merge the two (from my previous submission) to form one, these is where my vba knowledge is not at its best

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "Z6" Then
If Target.Value <> Target.Offset(-1).Value Or Target.Offset(-1).Value = "" Then
Application.EnableEvents = False
Target.ClearContents
Application.Goto reference:=Range("H6"), scroll:=True
MsgBox "Please choose a value then enter the same in Z6", vbExclamation
Application.EnableEvents = True
End If
End If
End Sub
 
Last edited:
Upvote 0
Just add more code at the end:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(False, False) = "Z6" Then
        If Target.Value <> Target.Offset(-1).Value Or Target.Offset(-1).Value = "" Then
            Application.EnableEvents = False
            Target.ClearContents
            Application.Goto reference:=Range("H6"), Scroll:=True
            MsgBox "Please choose a value then enter the same in Z6", vbExclamation
            Application.EnableEvents = True
        End If
    ElseIf Target.Address(False, False) = "H6" Then
        Select Case Target.Value
            Case "Camps Bay", "Tokai": Call unhide_rows
        End Select
    End If
End Sub
 
Upvote 0
Thanks Andrew,

I've done this and the macro is still not being called up, just wondering if "else" need to be there, as they are 2 seperate bits of code?
 
Upvote 0
The code works fine for me (there is an ElseIf in there). Maybe events are disabled, so go to the Immediate window in the VBE, type:

Application.EnableEvents = True

and press Enter.
 
Upvote 0
The code works fine for me (there is an ElseIf in there). Maybe events are disabled, so go to the Immediate window in the VBE, type:

Application.EnableEvents = True

and press Enter.

Let me approach this from the beginning:
If any of the names from list EK18:EK58 have been selected in H6, I would like rows A11:A14 to unhide.
Maybe this would makes things simpler
 
Upvote 0
Thats correct, when H6 name is selected the event does not fire, Z6 is out of the pic for now
and I did "Application.EnableEvents = True"
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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