Clearing contents not formatting

  • Thread starter Thread starter JSnow
  • Start date Start date
J

JSnow

I posted not too long ago and Gary's Student gave me the following code to
solve my problem:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set b = Range("D:D")
If Intersect(t, b) Is Nothing Then Exit Sub
If t.NumberFormat = "General" Then Exit Sub
Dim s As String
s = t.Value
If Left(s, 1) <> "=" Then Exit Sub
Application.EnableEvents = False
t.Clear
t.Formula = s
Application.EnableEvents = True
End Sub

The above code is designed to change the formatting of a cell from 'text' to
'general' if the user inputs an equal sign.

My only concern now is that the t.Clear line wipes out all the other
formatting too. Any suggestions on how to keep the background color and
indentation but swap out the text for general?
 
That doesn't work because we do need to clear the formatting to make it
general. Can we specifically clear the number formatting and not the
alignment, font, border, etc.?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top