Replace a blank cell with a string using if function

De Bruce

New Member
Joined
May 23, 2019
Messages
30
Good day all,
I have an uncommon challenge. I have a sheet named Sheet1 filled with data, I want a situation when I delete the values in a cell, instead of remaining blank, it will be filled with a string (example "x").
I tried using the IF function from Sheet2 to fill a blank cell in Sheet1
=IF(Sheet1!A5 = "", Sheet1!A5 = "X"). I keep getting an error FALSE from the cell I inserted the formula.
Is there any the get this right.
Thanks in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
A formula can only affect the cell that's it in.
To do what you want would need VBA
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the resulting window:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim cell As Range
    
    Application.EnableEvents = False
    
    For Each cell In Target
        If cell.Value = "" Then cell.Value = "x"
    Next cell
    
    Application.EnableEvents = True
    
End Sub
This code will automatically populate an "x" in any cell on that sheet that you manual delete the data out of.
 
Upvote 0
It works manually. However, how can I adjust the variable so It can automatically populate an "x" when deleting from a data entry form. Thanks once again.
 
Upvote 0
How exactly are you deleting it from a data entry form?
What does the code behind the data entry form look like?
That is probably where you will need to address it.
 
Upvote 0
It is the default data entry form that comes with excel. The data entry form is a faster way of imputing and deleting data in a cell. When I delete via the data entry form the x doesn't appear in the cell
 
Upvote 0
I may be off base, but took a different approach with the following that prompts you to enter the cells you want "deleted" and replaced with "xxxxx"...
Delimit the cells with a comma, such as: B3,C4

Code:
Sub Obfuscate()
Dim strg As String, nDelim As Integer, i As Integer, w As String, p As Integer
strg = InputBox("Cells to blank out?", "Obfuscate")
strg = strg & ","
nDelim = Len(strg) - Len(Replace(strg, ",", ""))
For i = 1 To nDelim
 p = WorksheetFunction.Find(",", strg)
 w = Left(strg, p - 1)
 Range(w) = "xxxxx"
 strg = Right(strg, Len(strg) - p)
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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