Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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? |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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? |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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? |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Conditional Formatting/Contents | Excel Worksheet Functions | |||
Selectively Clearing cell contents | Excel Worksheet Functions | |||
Clearing the Contents of Merged Cells | New Users to Excel | |||
Clearing Contents of Cell | Excel Worksheet Functions | |||
Clearing Contents but not Formulas | Excel Worksheet Functions |