Question on using Select Case

BHomestar

Board Regular
Joined
Nov 17, 2003
Messages
88
Hi everyone,

I was hoping someone could look at my code below and tell me how to leave cell(-1,1) unchanged if the three cases are not met. Right now the cell is turned to blank if the case is not met. Also, how can I change the activation of the procedure to clicking on cell C15 specifically instead of just any selection change? Would this be easier with an IF THEN?

Thanks for any help!!

Bryan


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range, answer As String
Set rng = Range([C15], [C15])
For Each cell In rng
Select Case cell
Case Is = "Fixed 30 Year": answer = "Not Applicable"
Case Is = "Fixed 20 Year": answer = "Not Applicable"
Case Is = "Fixed 15 Year": answer = "Not Applicable"
End Select
cell(-1, 1) = answer
n:
Next
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim answer As String
If Target.Address = "$C$15" Then
Select Case Target
Case Is = "Fixed 30 Year": answer = "Not Applicable"
Case Is = "Fixed 20 Year": answer = "Not Applicable"
Case Is = "Fixed 15 Year": answer = "Not Applicable"
Case Else: answer = Target(-1, 1)
End Select
Target(-1, 1) = answer
End If
End Sub
 
Upvote 0
Another option is to use the change event if the value of C15 is changed.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$15" And Target.Cells.Count = 1 Then
   If Target = "Fixed 30 Year" Or Target = "Fixed 20 Year" _
   Or Target = "Fixed 15 Year" Then
   Target(-1, 1) = "Not Applicable"
   End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,600
Messages
6,056,200
Members
444,850
Latest member
dancasta7

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