Conditional statements for dropdown list and cell formatting

rdoulaghsingh

Board Regular
Joined
Feb 14, 2021
Messages
105
Office Version
  1. 365
Platform
  1. Windows
I have 3 statuses in a dropdown list in Col C. namely "N/A", "Pending" and "Completed" and a date column in Col B. If the user selects N/A from the dropdown in Col C. it locks the date field to the left and provides some formatting to the field. However, if the user selects another status besides "N/A" it clears the formatting and N/A text from date field. I have the code below which does everything I need it to, except that if a date is entered into the field and then I select "completed" or "pending" it clears the field - which it shouldn't. Please help.

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next

If Target.Count = 1 Then
        If Not Intersect(Target, Range("C3:C13,C18:C28")) Is Nothing Then
            Application.EnableEvents = False
            If Target.Value = "N/A" Then
                With Target(1, 0)
                    .Value = "(N/A)"
                    .Enabled = False
                    With .Interior
                        .Pattern = xlLightDown
                        .TintAndShade = 0
                        .PatternTintAndShade = 0
                    End With
                End With
            Else
                With Target(1, 0)
                    .Value = ""
                    .Enabled = True
                    With .Interior
                        .Pattern = xlPatternNone
                        .TintAndShade = 0
                        .PatternTintAndShade = 0
                    End With
                End With
            End If
            Application.EnableEvents = True
        End If
    End If
    
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
VBA Code:
If .Value = "N/A" Then
                    .Value = ""
                    .Enabled = True
                    With .Interior
                        .Pattern = xlPatternNone
                        .TintAndShade = 0
                        .PatternTintAndShade = 0
                    End With
EndIf
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,287
Members
449,218
Latest member
Excel Master

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