Hello,
I have a sheet that user can update.
Columns A, C-G and I-J are text
Columns B and H are date format.
I force the format to consolas (to see difference between O and 0), set the date cells to yyyy-mm-dd, do some centering and indenting.
BUT: I do this inefficiently on all cells from row 2 to row 999 because I cannot figure out how to only manipulate the cells that are changed due to multiple formats being used.
What I use now (that works, but leaves me with far to large workbook on save):
[VBA]Sub Worksheet_Change(ByVal target As Range)
On Error Resume Next
If target.Row = 1 Then Exit Sub
Dim Changed_Cell_Address As String
Dim Cell_Range As Range
Changed_Cell_Address = target.Address
Application.EnableEvents = False
Set Cell_Range = Range(Changed_Cell_Address)
'Clear all cell formatting in updated cells
Cell_Range.ClearFormats
' Set cell format to standard Consolas font 9 for easy differentation of numbers
ActiveSheet.Unprotect
ActiveWorkbook.Unprotect
With Range(Changed_Cell_Address).Font
.Name = "Consolas"
.FontStyle = "Regular"
.Size = 9
End With
Range(Changed_Cell_Address).Locked = False
Range("A2", "A999").IndentLevel = 1
Range("B2", "B999").NumberFormat = "yyyy-mm-dd"
Range("B2", "B999").HorizontalAlignment = xlCenter
Range("G2", "G999").HorizontalAlignment = xlCenter
Range("H2", "H999").HorizontalAlignment = xlCenter
Range("I2", "I999").HorizontalAlignment = xlCenter
Application.Run "ThisWorkbook.ExcelDiet"
ActiveSheet.Protect
ActiveWorkbook.Protect
Application.EnableEvents = True
End Sub[/VBA]
how can I manipulate ONLY the changed cells?
I have a sheet that user can update.
Columns A, C-G and I-J are text
Columns B and H are date format.
I force the format to consolas (to see difference between O and 0), set the date cells to yyyy-mm-dd, do some centering and indenting.
BUT: I do this inefficiently on all cells from row 2 to row 999 because I cannot figure out how to only manipulate the cells that are changed due to multiple formats being used.
What I use now (that works, but leaves me with far to large workbook on save):
[VBA]Sub Worksheet_Change(ByVal target As Range)
On Error Resume Next
If target.Row = 1 Then Exit Sub
Dim Changed_Cell_Address As String
Dim Cell_Range As Range
Changed_Cell_Address = target.Address
Application.EnableEvents = False
Set Cell_Range = Range(Changed_Cell_Address)
'Clear all cell formatting in updated cells
Cell_Range.ClearFormats
' Set cell format to standard Consolas font 9 for easy differentation of numbers
ActiveSheet.Unprotect
ActiveWorkbook.Unprotect
With Range(Changed_Cell_Address).Font
.Name = "Consolas"
.FontStyle = "Regular"
.Size = 9
End With
Range(Changed_Cell_Address).Locked = False
Range("A2", "A999").IndentLevel = 1
Range("B2", "B999").NumberFormat = "yyyy-mm-dd"
Range("B2", "B999").HorizontalAlignment = xlCenter
Range("G2", "G999").HorizontalAlignment = xlCenter
Range("H2", "H999").HorizontalAlignment = xlCenter
Range("I2", "I999").HorizontalAlignment = xlCenter
Application.Run "ThisWorkbook.ExcelDiet"
ActiveSheet.Protect
ActiveWorkbook.Protect
Application.EnableEvents = True
End Sub[/VBA]
how can I manipulate ONLY the changed cells?