Option Explicit
Sub HighlightAll()
Dim rng As Range
Dim MyCol As Long
If ActiveCell.Interior.ColorIndex <> xlNone Then
MyCol = ActiveCell.Interior.ColorIndex
Else
MyCol = 6
End If
If Selection.Cells.Count > 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange
End If
If MsgBox("Highlight text?", vbYesNo) = vbNo Then
MyCol = xlNone
End If
TextHighlight rng, MyCol
End Sub
Sub HighlightColumn()
Dim rng As Range
Dim MyCol As Long
If ActiveCell.Interior.ColorIndex <> xlNone Then
MyCol = ActiveCell.Interior.ColorIndex
Else
MyCol = 8
End If
Set rng = Intersect(ActiveCell.EntireColumn, ActiveSheet.UsedRange)
If rng Is Nothing Then
MsgBox "Please select cell within UsedRange"
Exit Sub
End If
If MsgBox("Highlight text?", vbYesNo) = vbNo Then
MyCol = xlNone
End If
TextHighlight rng, MyCol
End Sub
Sub TextHighlight(rng As Range, MyCol As Long)
Dim cll As Range
Dim Cols As Long, i As Long
Dim MyWidth As Double, StWidth As Double, RunWidth As Double
Dim IndexCol As Long
Const AdjustRatio = 0.875
Application.ScreenUpdating = False
For Each cll In rng
If Len(cll) > 0 Then
StWidth = cll.ColumnWidth
cll.Columns.AutoFit
MyWidth = cll.ColumnWidth
cll.ColumnWidth = StWidth
i = 0
Cols = 0
Do
If i > 0 And cll.Offset(0, i) <> "" Then Exit Do
RunWidth = cll.Offset(0, i).ColumnWidth
Cols = Cols + RunWidth
cll.Offset(0, i).Interior.ColorIndex = MyCol
i = i + 1
Loop Until Cols > MyWidth * AdjustRatio
End If
Next
Application.ScreenUpdating = True
End Sub
|