![]() |
Clearing contents not formatting
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? |
Clearing contents not formatting
t.clearcontents
-- HTH... Jim Thomlinson "JSnow" wrote: 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? |
Clearing contents not formatting
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.? "Jim Thomlinson" wrote: t.clearcontents -- HTH... Jim Thomlinson "JSnow" wrote: 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? |
Clearing contents not formatting
from: Gary's Student:
Change: t.Clear to: t.NumberFormat = "General" -- Gary''s Student - gsnu200800 "JSnow" wrote: 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.? "Jim Thomlinson" wrote: t.clearcontents -- HTH... Jim Thomlinson "JSnow" wrote: 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? |
All times are GMT +1. The time now is 11:26 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com