Running code in Range EXCEPT if specific values are found in cell.

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Hello, again. My Worksheet_Change includes code a macro that runs when a value is entered in a cell in a Named Range. I'm trying to have the code NOT run if the cell's value is either a single blank space (" ") or contains a forward slash as part of the value ("*/*").

Here's the section...

VBA Code:
    Set KeyCells = Range("CalendarFloorsOrderNumberColumn")
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
    
    Application.EnableEvents = False
                   
    Call FloorOrderNumber
        
    Application.EnableEvents = True
    
    End If

Here's what I tried without success:

VBA Code:
    Set KeyCells = Range("CalendarFloorsOrderNumberColumn")
    Set Target = Application.Intersect(KeyCells, Range(Target.Address))
    If Target.Value = " " Then
    GoTo SkipBlank
    End If
    If Target.Value = "*/*" Then
    GoTo SkipBlank
    End If
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
    Application.EnableEvents = False
    Call FloorOrderNumber
    Application.EnableEvents = True
    End If
    SkipBlank:

Here's the complete code:

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

If Target.Cells.Count > 1 Or Target.HasFormula Or Target = "<ADD NEW>" Then Exit Sub

    On Error Resume Next

    If Not Intersect(Target, Range("ElevationColumn")) Is Nothing Then

        Application.EnableEvents = False

        Target = UCase(Target)

        Application.EnableEvents = True

    End If
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub

    On Error Resume Next

    If Not Intersect(Target, Range("SubLotColumn")) Is Nothing Then

        Application.EnableEvents = False
        
        If Trim(Target) <> "" Then
        Target = Application.Substitute(Target, "..", ".")
        End If
        
        If InStr(1, Target, "-") > 0 Then
        Target = UCase(Target)
        End If

        Application.EnableEvents = True

    End If

    On Error GoTo 0

    Dim KeyCells As Range
        
    Set KeyCells = Range("DateColumn")
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
    
    Application.EnableEvents = False
                   
    Call ChangeDate
        
    Application.EnableEvents = True
    
    End If
    
    If Not Intersect(Target, Range("DateColumn")) Is Nothing Then

    Application.EnableEvents = False

    Target = UCase(Target)

    Application.EnableEvents = True

    End If
         
    Set KeyCells = Range("CalendarFloorsOrderNumberColumn")
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
    
    Application.EnableEvents = False
                   
    Call FloorOrderNumber
        
    Application.EnableEvents = True
    
    End If
 
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
This works:

VBA Code:
    Set KeyCells = Range("CalendarFloorsOrderNumberColumn")
    If Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then Exit Sub
    If Target <> " " Or If Target <> "*/*" Then
        Application.EnableEvents = False
        Call FloorOrderNumber
        Application.EnableEvents = True
    End If

Now I work on the second condition (*/*)
 
Upvote 0
Tried this, but only the second condition ("*/*") works:

VBA Code:
    Set KeyCells = Range("CalendarFloorsOrderNumberColumn")
    If Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then Exit Sub
    If Target <> " " Or Target <> "*/*" Then
        Application.EnableEvents = False
        Call FloorOrderNumber
        Application.EnableEvents = True
    End If
 
Upvote 0
Figured it out. Slight change:

VBA Code:
    Set KeyCells = Range("CalendarFloorsOrderNumberColumn")
    If Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then Exit Sub
    If Target <> " " And Target <> "*/*" Then
        Application.EnableEvents = False
        Call FloorOrderNumber
        Application.EnableEvents = True
    End If
 
Upvote 0
Solution

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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