Adding default values to cells

willhaywood

New Member
Joined
Jul 25, 2008
Messages
10
Hi All,

I am having some difficulty adding a default value to a cell.

What I want to do is have a cell that will read "Enter value here" if nothing has been added, but display the users text when changed.

I've been playing with the IF statement feature for a while, but am getting nowhere.

Any ideas?

Thanks

Will
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Thanks,

I did consider that, but there are two many instances where I need to have an "enter value here" cell on the sheet I am using and it becomes too clutered :(

Will
 
Last edited:
Upvote 0
Hi Will,

Is it the entire sheet or just certain ranges? You could maybe use something like this?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("B2:B100")) Is Nothing Then
    For Each cell In Range("B2:B100")
        If cell.Value = "" Then
            cell.Value = "Please Enter value here"
        End If
        
    Next cell
    DoEvents
End If

End Sub
 
Upvote 0
Hi mike,

Thanks for your response. It is certain ranges within the spreadsheet. I'm a bit of a VB noob, where should I be putting the code?

Thanks

Will
 
Upvote 0
Hi,

From Excel, Right click on the sheet tab this is relevant for and click on view code.

Paste this in;

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, [B][COLOR="Red"]Range("B2:B100")[/COLOR][/B]) Is Nothing Then
    For Each cell In [B][COLOR="red"]Range("B2:B100")[/COLOR][/B]
        If cell.Value = "" Then
            cell.Value = "Please Enter value here"
        End If
        
    Next cell
    DoEvents
End If

End Sub

Please note that the range of cells that you wish to affect are Bold and Red and you need to change both sets.

If you have two seperate ranges of cells or more you can ammend the code as such;

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, [B][COLOR="Red"]Range("B2:B100,D4:D8,G8:G14")[/COLOR][/B]) Is Nothing Then
    For Each cell In [B][COLOR="red"]Range("B2:B100,D4:D8,G8:G14")[/COLOR][/B]
        If cell.Value = "" Then
            cell.Value = "Please Enter value here"
        End If
        
    Next cell
    DoEvents
End If

End Sub

Give it a try and see if it solves your problem.
 
Upvote 0
Hi Mike,

I have the code in the "this workbook" window (as pops up when view code is selected), but there is no change to the cells selected. Both sets of values are the same (eg b1:b100) but nothing is changing.

Thanks

Will
 
Upvote 0
That needs to be in the workSHEET code module :), not the workBOOK code module. Right click on the applicable sheet tab at the bottom of your window. "View Code" is the very bottom choice.
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

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