Wednesday, February 11, 2015

Macro to Highlight Cells over 30 Chars (Scrubbing Data Pre Load)

When loading data into an delivered Component via CI, sometimes you get data that is larger than the target field's length.  For instance, 30 characters for the Field DESCR.

This macro will highlight a cell yellow if it is over the 30 Characters.  This identifies what data will be truncated.  Change the col variable, currently it is set to 3, this would be column C.  The macro also starts on the activecell, so highlight the row you want the macro to begin.


Sub scan()
Dim i As Long
Dim s As Long
Dim o As Long
Dim col As Long
Dim tgt As Long
 
 tgt = 30
 col = 3
 s = ActiveCell.Row
 For i = ActiveCell.Row To Rows.Count
  
 If Len(Cells(i, col).Value) > tgt Then
  Cells(i, col).Interior.ColorIndex = 6
  ActiveCell.Offset(o, 0).Select
  
   
 End If

Next i
End Sub

Results:


1 comment: