excelbytes
Active Member
- Joined
- Dec 11, 2014
- Messages
- 291
- Office Version
- 365
- Platform
- Windows
I have several procedures in the Worksheet_Change procedure. The first three work fine. The last one highlighted in red at the end below is where I have an issue. I think I need to implement a looping procedure but don't know how to do that properly. What I want to occur is as follows:
Cells B15:B50 can have either an "H" or "K" in it. Any number of these cells can have either. So cell B15 can be "K", B16 can be "H", B17 can be "H", B18 can be "K", etc.
If an "H" is in any of the cells in B15:B50, the corresponding cell in column H needs to have a drop down list based on this:
If a "K" is in any of the cells in B15:B50, the corresponding cell in column H needs to have a drop down list based on this:
So H15 could have a different drop down list than H16, than H17, etc.
Here is the complete code:
Currently I get a "type mismatch" error 13 when I enter anything in those cells.
I hope this is clear enough.
Thanks in advance for your help.
Cells B15:B50 can have either an "H" or "K" in it. Any number of these cells can have either. So cell B15 can be "K", B16 can be "H", B17 can be "H", B18 can be "K", etc.
If an "H" is in any of the cells in B15:B50, the corresponding cell in column H needs to have a drop down list based on this:
VBA Code:
Set rngLookup = Worksheets("HYUNDAI").Range("P2:R107")
Application.EnableEvents = False
Target.Value = Application.VLookup(Target.Value, rngLookup, 2, False)
Application.EnableEvents = True
If a "K" is in any of the cells in B15:B50, the corresponding cell in column H needs to have a drop down list based on this:
VBA Code:
Set rngLookup = Worksheets("KIA").Range("P2:R75")
Application.EnableEvents = False
Target.Value = Application.VLookup(Target.Value, rngLookup, 2, False)
Application.EnableEvents = True
So H15 could have a different drop down list than H16, than H17, etc.
Here is the complete code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngLookup As Range
If Not Intersect(Target, Range("L15:L50")) Is Nothing Then
If Len(Trim(Target.Value)) = 0 Then
Exit Sub
End If
Set rngLookup = Worksheets("FORM DETAILS").Range("E4:G25")
Application.EnableEvents = False
Target.Value = Application.VLookup(Target.Value, rngLookup, 2, False)
Application.EnableEvents = True
End If
If Not Intersect(Target, Range("P15:P50")) Is Nothing Then
If Len(Trim(Target.Value)) = 0 Then
Exit Sub
End If
Set rngLookup = Worksheets("FORM DETAILS").Range("H4:J5")
Application.EnableEvents = False
Target.Value = Application.VLookup(Target.Value, rngLookup, 2, False)
Application.EnableEvents = True
End If
If Not Intersect(Target, Range("M15:M50")) Is Nothing Then
If Len(Trim(Target.Value)) = 0 Then
Exit Sub
End If
Set rngLookup = Worksheets("FORM DETAILS").Range("B4:D13")
Application.EnableEvents = False
Target.Value = Application.VLookup(Target.Value, rngLookup, 2, False)
Application.EnableEvents = True
End If
[B][COLOR=rgb(184, 49, 47)] If Worksheets("OFFICIAL DRAFT").Range("B15:B50") = "K" Then[/COLOR][/B]
[COLOR=rgb(184, 49, 47)][B]
If Not Intersect(Target, Range("H15:H50")) Is Nothing Then
If Len(Trim(Target.Value)) = 0 Then
Exit Sub
End If
Set rngLookup = Worksheets("KIA").Range("P2:R75")
Application.EnableEvents = False
Target.Value = Application.VLookup(Target.Value, rngLookup, 2, False)
Application.EnableEvents = True
End If
Else
If Worksheets("OFFICIAL DRAFT").Range("B15:B50") = "H" Then
If Not Intersect(Target, Range("H15:H50")) Is Nothing Then
If Len(Trim(Target.Value)) = 0 Then
Exit Sub
End If
Set rngLookup = Worksheets("HYUNDAI").Range("P2:R107")
Application.EnableEvents = False
Target.Value = Application.VLookup(Target.Value, rngLookup, 2, False)
Application.EnableEvents = True
End If
End If
End If
[/B][/COLOR]
[B][COLOR=rgb(184, 49, 47)]End Sub[/COLOR][/B]
Currently I get a "type mismatch" error 13 when I enter anything in those cells.
I hope this is clear enough.
Thanks in advance for your help.