View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
homer homer is offline
external usenet poster
 
Posts: 47
Default Display feet inches and fraction

Rick,

Thanks for your help. I input the feet then a space, inches then a space
and then the fraction. The code worked except that I would get two inch
marks at the end of the dimension. When I removed two of the six inch
(quotation) marks toward the end of the code, only one inch mark shows up.
This seems to work for what I need.

Thanks,

Homer

"Rick Rothstein (MVP - VB)" wrote:

I would like to be able to input 11 3 1/2 and have the cell display
as 11'-3 1/2" Is this possible?


Right-click the sheet tab for the sheet you want this functionality on and
select View Code on the popup menu that appears. Copy/Paste the following
into the code window that opened up in the VBA editor...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As Long
Dim TargetPattern As String
TargetPattern = Target.Value
For X = 1 To Len(Target.Value)
If InStr(" /", Mid$(TargetPattern, X, 1)) = 0 Then
Mid$(TargetPattern, X, 1) = "#"
End If
Next
On Error GoTo Whoops
Application.EnableEvents = False
If Target.Value Like TargetPattern Then
Target.Value = Replace(Target.Value, " ", "'-", , 1) & """"""
End If
Whoops:
Application.EnableEvents = True
End Sub

If you enter a number in the format you showed (with only single spaces
between the numbers), then it will be reformatted the way you want.

Rick