Combine two Worksheet_Change

Francesca_0208

Board Regular
Joined
Apr 25, 2014
Messages
59
I've had a look at the other threads but I'm getting confused and the more I seem to change the more seems to go wrong! I have these two:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = ActiveSheet.Range("d7").Address Then
If Target = "Approval" Then
ActiveSheet.Tab.Color = RGB(255, 192, 218)
ActiveSheet.Range("D7").Interior.Color = RGB(255, 255, 255)
ElseIf Target = "Information" Then
ActiveSheet.Tab.Color = RGB(255, 192, 218)
ActiveSheet.Range("D7").Interior.Color = RGB(255, 255, 255)
ElseIf Target = "C" Then
ActiveSheet.Tab.Color = RGB(255, 192, 218)
ActiveSheet.Range("D7").Interior.Color = RGB(255, 255, 255)
ElseIf Target = "B" Then
ActiveSheet.Tab.Color = RGB(255, 192, 218)
ActiveSheet.Range("D7").Interior.Color = RGB(255, 255, 255)
Else
ActiveSheet.Tab.ColorIndex = xlColorIndexNone
ActiveSheet.Range("D7").Interior.Color = xlNone
End If
End If

Dim cell As Range
Dim Num As Long


For Each cell In Intersect(Target, Range("C11:C38"))
If cell <> "" Then
Application.EnableEvents = False
Num = Application.WorksheetFunction.Match(cell.Text, _
Sheets("Data Fields").Range("Product"), 0)
If Num <> 0 Then cell.Formula = "=INDEX(Product, " & Num & ")"
Application.EnableEvents = True
End If

Next cell
End Sub

&

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim Num As Long


For Each cell In Intersect(Target, Range("C11:C38"))
If cell <> "" Then
Application.EnableEvents = False
Num = Application.WorksheetFunction.Match(cell.Text, _
Sheets("Data Fields").Range("Product"), 0)
If Num <> 0 Then cell.Formula = "=INDEX(Product, " & Num & ")"
Application.EnableEvents = True
End If
Next cell


End Sub

And they seem to work on their own but any way I try to combine the two doesn't work.

Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I think I've worked out the problem and I'm getting an error for the second lot of code, it's a Run time error 424, object required. I can only guess it's to do with the Intersect code but I don't really understand it.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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