Worksheet Change Problem

smpatty08

Board Regular
Joined
May 16, 2014
Messages
155
I'm sure there is an easy solution to this, but I can't figure it out. I am trying to create a form in Excel that has multiple drop down lists and I would like to have a macro that will replace some cell values with "N/A" is no is selected from the drop down. I can get it to work on this first, but I can't get it to recognize the second change. Here is what I have so far.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 If Target.Address = "$C$16" Then
    If Range("C16").Value = "No" Then
        Range("C18").Value = "N/A"
        Range("D21").Value = "N/A"
        Range("F21").Value = "N/A"
        Range("C23").Value = "N/A"
    Else
        Range("C18").Value = ""
        Range("D21").Value = ""
        Range("F21").Value = ""
        Range("C23").Value = ""
    End If
 End If
 End Sub
 Private Sub Worksheet_Change1(ByVal Target As Range)
 If Target.Address = "$D$25" Then
    If Range("D25").Value = "No" Then
        Range("D27").Value = "N/A"
        Range("C29").Value = "N/A"
        Range("F29").Value = "N/A"
    Else
        Range("D27").Value = ""
        Range("C29").Value = ""
        Range("F29").Value = ""
    End If
 End If
 End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Worksheet_Change is a special event procedure that runs automatically when a cell changes. In order for it to work, it MUST be named a certain way. If you change its name, it is not recognized.
And you can only have one Worksheet_Change procedure per sheet. So you need to combine your code into a single procedure with that specific name.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
 If Target.Address = "$C$16" Then
    If Range("C16").Value = "No" Then
        Range("C18").Value = "N/A"
        Range("D21").Value = "N/A"
        Range("F21").Value = "N/A"
        Range("C23").Value = "N/A"
    Else
        Range("C18").Value = ""
        Range("D21").Value = ""
        Range("F21").Value = ""
        Range("C23").Value = ""
    End If
 End If

 If Target.Address = "$D$25" Then
    If Range("D25").Value = "No" Then
        Range("D27").Value = "N/A"
        Range("C29").Value = "N/A"
        Range("F29").Value = "N/A"
    Else
        Range("D27").Value = ""
        Range("C29").Value = ""
        Range("F29").Value = ""
    End If
 End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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