Select Case question

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,380
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to try to update cells automatically but it is not doing what I need;

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("D7").Value = "" Then
Select Case Range("D7").Value
Case Is > 8
Range("E7").Value = "Current"
End Select
Else
Select Case Range("D7").Value
Case Is < 1
Range("E7").Value = "Expired"
Case 1 To 8
Range("E7").Value = "Due to Expire"
End Select
End If

End Sub

The cell in E7 has Data Validation List and what I need is it to allow any value from that list if D7 is empty, (D7 contains a formula which does give "" if the source cell is empty). What is happening is that E7 is defaulting to 'Current'.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,350
Try

Code:
If CStr(Range("D7").Value) <> "" Then
    Select Case Val(CStr(Range("D7").Value))
        Case Is < 1 Then
            Range("E7").Value = "Expired"
        Case Is < 8 Then
            Range("E7").Value = "Due To Expire"
        Case Else
            Range("E7").Value = "Current"
    End Select
End If
 
Upvote 0

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,380
Office Version
  1. 2016
Platform
  1. Windows
Thanks Mike, but I get a syntax error with this line highlighted;

Code:
Case Is < 1 Then
 
Upvote 0

Forum statistics

Threads
1,195,940
Messages
6,012,426
Members
441,699
Latest member
tnlbado

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
Top