Berenloper
Board Regular
- Joined
- May 28, 2009
- Messages
- 83
- Office Version
- 365
- Platform
- Windows
Hi everyone,
I'm trying to change the cell format if a cell will be effected by a VBA trim-function.
This is the code I have:
The code works fine when Line Feed and Carriage return characters are present.
So, I like to have the same when unnecessary spaces are present (but not yet have to be removed), just to see which cells will be effected.
Now they are removed by the code "xCell.Value = Application.Trim(xCell.Value)"
Does anyone has an idea?
Regards,
Berenloper
I'm trying to change the cell format if a cell will be effected by a VBA trim-function.
This is the code I have:
VBA Code:
Sub DataCheck()
Dim xRg As Range
Dim xCell As Range
Dim counter As Integer
On Error Resume Next
counter = 0
MsgBox ("Starting Check...")
Set xRg = Range("RangeCheck") 'A given Range
Application.ScreenUpdating = False
For Each xCell In xRg
If Not IsEmpty(xCell.Value) Then
xCell.Value = Application.Trim(xCell.Value) 'Remove unnecessary spaces
If 0 < InStr(xCell, Chr(10)) Then 'xCell = Replace(xCell, Chr(10), "") 'Check for Line Feed character
counter = counter + 1
With xCell.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
End With
With xCell.Font
.Color = -16777024
End With
End If
If 0 < InStr(xCell, Chr(34)) Then 'xCell = Replace(xCell, Chr(34), "") 'Check for Carriage Return character
counter = counter + 1
With xCell.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
End With
With xCell.Font
.Color = -16777024
End With
End If
End If
Next
Application.ScreenUpdating = True
MsgBox ("Check finished. There are " & counter & " errors found!")
End Sub
The code works fine when Line Feed and Carriage return characters are present.
So, I like to have the same when unnecessary spaces are present (but not yet have to be removed), just to see which cells will be effected.
Now they are removed by the code "xCell.Value = Application.Trim(xCell.Value)"
Does anyone has an idea?
Regards,
Berenloper