VBA - Leave value as is

Oranjin

Board Regular
Joined
Mar 16, 2016
Messages
81
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim rw As Long, fn As Range
Application.EnableEvents = False
    If Not Intersect(Target, Range("Entry")) Is Nothing Then
        Set fn = Range("J:J").Find(Target.Value, , xlValues, xlWhole)
            If Not fn Is Nothing Then
                rw = fn.Row
                Range("B" & rw).Resize(1, 11).ClearContents
                Range("B" & rw) = "Open"
                Range("D" & rw) = "4"
                Range("E" & rw) = "NW"
                Range("G" & rw) = "Open Slot"
                Range("J" & rw) = "open Slot"
                Range("K" & rw) = "4030"
                Range("L" & rw) = "West 86"
            End If
    End If
Application.EnableEvents = True
End Sub

for rows D,E,K and L instead of entering the specified value, I'd like this Macro to, "Leave the contents of the cell as is".

So, if it says, 4030, then leave it as 4030. If it says 4031, then I'd like it to stay as 4031 (or the formula I have in the cell that pulls up that value).

Can someone help me understand how to make it leave the cell as is instead of entering this generic text? Thanks

Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
See if this code works for you (note: not tested):
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim rw As Long, fn As Range
Application.EnableEvents = False
    If Not Intersect(Target, Range("Entry")) Is Nothing Then
        Set fn = Range("J:J").Find(Target.Value, , xlValues, xlWhole)
            If Not fn Is Nothing Then
                rw = fn.Row
                'Range("B" & rw).Resize(1, 11).ClearContents
                Range("B" & rw).Resize(1, 2).ClearContents
                Range("F" & rw).Resize(1, 5).ClearContents
                Range("B" & rw) = "Open"
                'Range("D" & rw) = "4"
                'Range("E" & rw) = "NW"
                Range("G" & rw) = "Open Slot"
                Range("J" & rw) = "open Slot"
                'Range("K" & rw) = "4030"
                'Range("L" & rw) = "West 86"
            End If
    End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

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