Can two worksheet change function be used?

js1537

New Member
Joined
May 8, 2012
Messages
21
Hi,

I am using two worksheet change function in my below vba coding. But getting ambiguity error while running code. Please assist.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)</SPAN></SPAN>
If Intersect(Target, [b7]) Is Nothing Then Exit Sub</SPAN></SPAN>
Select Case [b7].Value</SPAN></SPAN>
Case "Existing GCIS Group - No Changes": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 1</SPAN></SPAN>
Case "Close GCIS Group": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 1</SPAN></SPAN>
Case "Existing GCIS Group - Changes": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0</SPAN></SPAN>
Case "New to GCIS": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0</SPAN></SPAN>
'Case Else: Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0</SPAN></SPAN>
End Select</SPAN></SPAN>
End Sub</SPAN></SPAN>

Private Sub Worksheet_Change(ByVal Target As Excel.Range)</SPAN></SPAN>
If Intersect(Target, [b46]) Is Nothing Then Exit Sub</SPAN></SPAN>
Select Case [b46].Value</SPAN></SPAN>
Case "Close GCIS Client - No Limits in Place": Range("B48:B66").Interior.ColorIndex = 1</SPAN></SPAN>
Case "Existing GCIS Client - No Changes": Range("B48:B66").Interior.ColorIndex = 1</SPAN></SPAN>
Case "Existing GCIS Client - Changes": Range("B47:b66").Interior.ColorIndex = 0</SPAN></SPAN>
Case "New to GCIS": Range("B48:b66").Interior.ColorIndex = 0</SPAN></SPAN>
Case "Delete/Inactive GCIS Client - No Longer Trading": Range("B48:b66").Interior.ColorIndex = 1</SPAN></SPAN>
'Case Else: Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0</SPAN></SPAN>
End Select</SPAN></SPAN>
End Sub</SPAN></SPAN>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You need to combine them like this

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, [b7]) Is Nothing Then
Select Case [b7].Value
Case "Existing GCIS Group - No Changes": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 1
Case "Close GCIS Group": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 1
Case "Existing GCIS Group - Changes": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
Case "New to GCIS": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
'Case Else: Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
End Select
ElseIf Not Intersect(Target, [b46]) Is Nothing Then
Select Case [b46].Value
Case "Close GCIS Client - No Limits in Place": Range("B48:B66").Interior.ColorIndex = 1
Case "Existing GCIS Client - No Changes": Range("B48:B66").Interior.ColorIndex = 1
Case "Existing GCIS Client - Changes": Range("B47:b66").Interior.ColorIndex = 0
Case "New to GCIS": Range("B48:b66").Interior.ColorIndex = 0
Case "Delete/Inactive GCIS Client - No Longer Trading": Range("B48:b66").Interior.ColorIndex = 1
'Case Else: Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
End Select
End If
End Sub
 
Upvote 0
Perhaps.
Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Not Intersect(Target, [b7]) Is Nothing Then
        Select Case [b7].Value
            Case "Existing GCIS Group - No Changes": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 1
            Case "Close GCIS Group": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 1
            Case "Existing GCIS Group - Changes": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
            Case "New to GCIS": Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
                'Case Else: Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
        End Select
    End If

    If Not Intersect(Target, [b46]) Is Nothing Then
        Select Case [b46].Value
            Case "Close GCIS Client - No Limits in Place": Range("B48:B66").Interior.ColorIndex = 1
            Case "Existing GCIS Client - No Changes": Range("B48:B66").Interior.ColorIndex = 1
            Case "Existing GCIS Client - Changes": Range("B47:b66").Interior.ColorIndex = 0
            Case "New to GCIS": Range("B48:b66").Interior.ColorIndex = 0
            Case "Delete/Inactive GCIS Client - No Longer Trading": Range("B48:b66").Interior.ColorIndex = 1
                'Case Else: Range("B16:B30,B32:B34,B36:B39,J29:J30").Interior.ColorIndex = 0
        End Select
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,206,834
Messages
6,075,134
Members
446,123
Latest member
junkyardforme

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