Replacing delete with a value

mecerrato

Board Regular
Joined
Oct 5, 2015
Messages
174
Office Version
  1. 365
Platform
  1. Windows
I have code that executes an autofilter to show data based on the value in cell d6. However, when the user hits the delete key the autofilter shows now data. If the user hits delete on d6 I would like to make the value of the cell 0.
Is this possible?

Code when there is a change:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Sheets("Main").Unprotect Password:="Mortgage1"
If Target.Address = "$B$6" Then
    If Range("d6").Value > 0 Then
    Call LO_and_Rate_Name_Change
    Else
    Call LO_Name_Change
End If
End If

If Target.Address = "$B$7" Then

    Call Borrower_Name_Change
End If

If Target.Address = "$B$8" Then
    Call Rate_Name_Change
End If

If Target.Address = "$D$6" Then
    If Range("b6").Value = "" Then
    MsgBox "Please Select an LO", vbOKCancel
    Range("b6").Select
    Else
    Call LO_and_Rate_Name_Change
End If
End If

End Sub

Code executed when there is a change in cell d6
VBA Code:
Sub LO_and_Rate_Name_Change() 'Borrower Dropdown list
ActiveSheet.Unprotect
Dim mysht As Worksheet
Dim myDropDown As Shape
Dim myVal As String
Dim myVal_LO As String
Dim r As Range
Set r = ActiveSheet.Range("$a$21:$v$10000")
Set mysht = ThisWorkbook.Worksheets("Data")
myVal = ActiveSheet.Range("$d$6").Value
myVal_LO = ActiveSheet.Range("$b$6").Value
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
  ActiveSheet.ShowAllData
End If
    ActiveSheet.Range("$a$21:$v$10000").AutoFilter Field:=6, Criteria1:=">" & myVal
    ActiveSheet.Range("$a$21:$v$10000").AutoFilter Field:=2, Criteria1:=myVal_LO
    Range(Cells(r.Rows.Count, 1), Cells(Rows.Count, Columns.Count)).EntireRow.Hidden = True
    Range("$a$21:$v$10000").Sort Key1:=Range("c21"), Order1:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
ActiveWindow.ScrollColumn = 1
Application.EnableEvents = False
Range("b7:b8").Value = Null

Application.EnableEvents = True
'Range("A11").Select
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I am probably missing something something here but don't you just need to add the line below:

Rich (BB code):
    If Target.Address = "$D$6" Then
        If Target.Value = "" Then Target.Value = 0  ' if D6 deleted replace blank with 0
        
        If Range("b6").Value = "" Then
            MsgBox "Please Select an LO", vbOKCancel
            Range("b6").Select
        Else
            Call LO_and_Rate_Name_Change
    End If
 
Upvote 0
Solution
I am probably missing something something here but don't you just need to add the line below:

Rich (BB code):
    If Target.Address = "$D$6" Then
        If Target.Value = "" Then Target.Value = 0  ' if D6 deleted replace blank with 0
       
        If Range("b6").Value = "" Then
            MsgBox "Please Select an LO", vbOKCancel
            Range("b6").Select
        Else
            Call LO_and_Rate_Name_Change
    End If
sorry sometimes it is right in front of you and you can't see it, thanks
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,096
Latest member
Anshu121

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