Karlbirger
Board Regular
- Joined
- Sep 21, 2011
- Messages
- 68
Hi guys,
And good morning to you all (dependning on if you on the plus side of GMT).
This is my first post in this forum, and I'm grateful for any help you pro's can give me. I have tried to solve this problem for myself for two days now (while I've searched google the same time for the answer). But I can't find any answer to this problem.
Software in use: Windows Vista & Excel 2007
What I want to do
I want to call a validation dropdown list in cell J6, based on what input you choose from the validation dropdown list in cell I6.
Both lists contains only text, and the list in cell I6 have three options to choose from: "Real estate", "Energy", or "Other".
Based on which one of these three you choose, one specific validation dropdown list should appear in cell J6 (the list connected to either real estate, energy, or other).
What I have done
I have tried several different techniques, ranging from cowboy vba in modules to worksheet_change and calculate in the worksheet. My latest grasp for a correct code looks like the following.
When I run this code, I get an error message:
"Run-time error '1004':
Application-defined or object-defined error"
The first line of code the debugger hits at is the one in bold below:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("I6") = "Real estate" Then
Okey, that's about it. I hope the information above is enough to get around and come closer to a solution.
Thanks in advance.
Johan
And good morning to you all (dependning on if you on the plus side of GMT).
This is my first post in this forum, and I'm grateful for any help you pro's can give me. I have tried to solve this problem for myself for two days now (while I've searched google the same time for the answer). But I can't find any answer to this problem.
Software in use: Windows Vista & Excel 2007
What I want to do
I want to call a validation dropdown list in cell J6, based on what input you choose from the validation dropdown list in cell I6.
Both lists contains only text, and the list in cell I6 have three options to choose from: "Real estate", "Energy", or "Other".
Based on which one of these three you choose, one specific validation dropdown list should appear in cell J6 (the list connected to either real estate, energy, or other).
What I have done
I have tried several different techniques, ranging from cowboy vba in modules to worksheet_change and calculate in the worksheet. My latest grasp for a correct code looks like the following.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("I6") = "Real estate" Then
Range("J6").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Real"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Elseif Range("I6") = "Energy" Then
Range("J6").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Energy"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Elseif Range("I6") = "Other" Then
Range("J6").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Other"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
End Sub
When I run this code, I get an error message:
"Run-time error '1004':
Application-defined or object-defined error"
The first line of code the debugger hits at is the one in bold below:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("I6") = "Real estate" Then
Code:
Range("J6").Select
With Selection.Validation
.Delete
[B] .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Real"[/B]
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ElseIf Range("I6") = "Energy" Then...
etc...
Okey, that's about it. I hope the information above is enough to get around and come closer to a solution.
Thanks in advance.
Johan