ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excell cell formatting (https://www.excelbanter.com/excel-programming/376281-excell-cell-formatting.html)

Matt Hannan

Excell cell formatting
 
I would like a selection of cells to display "-" unless text or a number is
typed in. However, if the text / number is subsequently deleted, I would like
the cell to revert back to "-".

Almost like the default content for the cell is "-" and not blank / empty


Gary''s Student

Excell cell formatting
 
Put the following in Worksheet code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B9")) Is Nothing Then
Else
If IsEmpty(Target) Then
Target.Value = "-"
End If
End If
End Sub

It sets up cell B9. Just expand the Intersect to include as many cells as
you need.

REMEMBER: worksheet code.
--
Gary's Student


"Matt Hannan" wrote:

I would like a selection of cells to display "-" unless text or a number is
typed in. However, if the text / number is subsequently deleted, I would like
the cell to revert back to "-".

Almost like the default content for the cell is "-" and not blank / empty


PCLIVE

Excell cell formatting
 
One way:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each cell In Range("A1:A10")
If cell.Value = "" Then cell.Value = "-"
Next cell
End Sub

Right-click on your worksheet tab, then click "View Code". Paste the above
code. Adjust the range as necessary.

Regards,
Paul

"Matt Hannan" <Matt wrote in message
...
I would like a selection of cells to display "-" unless text or a number is
typed in. However, if the text / number is subsequently deleted, I would
like
the cell to revert back to "-".

Almost like the default content for the cell is "-" and not blank / empty





All times are GMT +1. The time now is 03:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com