sense_sven
New Member
- Joined
- Feb 10, 2015
- Messages
- 2
Dear all,
I looked up several posts within this and other forums but I cannot get my code to work. One of the reasons might be that I am absolutely VBA-naive ... Here is the simple problem:
I have a drop-down (via Data - Data validation - list) in cell D8 of a Excel 2013 work sheet. I inserted a command button which I renamed in the "Name Box" to FillTableButton (a click on the button fills up all empty cells of a cell range via a macro). What I want is that the command button only appears i.e. is visible when a certain value is selected in the drop-down i.e. "Individualized" (without ""). In addition a message box should appear. Below is my code that does not work. Whenever I change the drop-down an error message appears "Runtime error '424': Object required". The debugger marks the line below in red (but I do not know why).
I hope somebody has an idea.
Sven
Code starts here
---
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("D8")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
If Range("D8").Value = "Individualized" Then
FillTableButton.Visible = True ' marked in debugger whenever I select Individualized
MsgBox "Make sure that you complete the table with individual hourly rates on the right >>"
Else
FillTableButton.Visible = False ' marked in debugger whenever I select others
End If
End If
End Sub
I looked up several posts within this and other forums but I cannot get my code to work. One of the reasons might be that I am absolutely VBA-naive ... Here is the simple problem:
I have a drop-down (via Data - Data validation - list) in cell D8 of a Excel 2013 work sheet. I inserted a command button which I renamed in the "Name Box" to FillTableButton (a click on the button fills up all empty cells of a cell range via a macro). What I want is that the command button only appears i.e. is visible when a certain value is selected in the drop-down i.e. "Individualized" (without ""). In addition a message box should appear. Below is my code that does not work. Whenever I change the drop-down an error message appears "Runtime error '424': Object required". The debugger marks the line below in red (but I do not know why).
I hope somebody has an idea.
Sven
Code starts here
---
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("D8")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
If Range("D8").Value = "Individualized" Then
FillTableButton.Visible = True ' marked in debugger whenever I select Individualized
MsgBox "Make sure that you complete the table with individual hourly rates on the right >>"
Else
FillTableButton.Visible = False ' marked in debugger whenever I select others
End If
End If
End Sub