View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
JSnow JSnow is offline
external usenet poster
 
Posts: 54
Default Change cell format from text to general on the fly

First off, thanks! I updated column A:A to D:D and pasted your code below
another bit of code already called "Private Sub Worksheet_Change(ByVal Target
As Range)" and got a compile error: Ambiguous name detected:
Worksheet_Change. Is there a way for me to include the new code w/ the old?
Here's the original code:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo Whoops
If Target.Count = 1 Then
If Target.Column = 3 Then 'this number picks the column: 1 is
column A, 2 is column B etc
If Target.Row 1 Then 'ignore row 1 which is probably a header
Target.Value = UCase(Target.Value)
End If
End If
If Target.Column = 5 Then 'this number picks the column: 1 is
column A, 2 is column B etc
If Target.Row 1 Then 'ignore row 1 which is probably a header
Target.Value = StrConv(Target.Value, vbProperCase)
End If
End If
End If

Whoops:
Application.EnableEvents = True

End Sub

"Mike H" wrote:

Hi,

Providing the formula are simple then this should do the trick. If you
expand into array formula then this will fail. Right click the sheet tab,
view code and paste this in

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A:A"
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Target.NumberFormat = "General"
Target.Formula = Target.Formula
End If
Application.EnableEvents = True
End Sub

Mike



"JSnow" wrote:

I don't know if this is possible (although anything seems possible with vba),
but here's what I'm attempting. I'm using Excel 2003 and I have a column
formatted as 'text'. I'd like to switch any cell in that column to 'general'
formatting once the user enter '=' in the cell to start a formula. These
formulas will be very simple, basically linking the text data from one cell
to the current cell.

I can do this manually by selecting the cell, format cell number text,
then enter my formula '=D12'. But I'm working with alot of data and it would
be much easier to have this format change on the fly when I enter the leading
equal sign.

I'm brand new to this forum, so thanks in advance for any direction.