Share via

conditional formatting certain text string

Anonymous
2013-06-23T07:00:56+00:00

I have a text string in cells located in a range of B7:H50. My text string contains an ampersand and a number 1 to 1000.  I would like it to run in a VBA code but not totally necessary. Here is a sample of my text string. 

COLUMN D

Row 8   AMG&2    410   06/01/2013

Row 9   TTI&3 440 06/04/2013

Row 10   ABC&555 560 06/12/2013

So in this example &2, &3 and &555 would be highlighted in white so it won't be visible. So "AMG&2    410   06/01/2013" is all one text string in Cell D8.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-06-23T07:38:00+00:00

Sub BlankAmp()

' change occurrence of &followed by characters up to a space to be white

  Dim C As Range

  Dim iStart As Integer

  Dim iEnd As Integer

  For Each C In Selection.Cells  ' Change Selection to Range("B7:H50")

    If Not C.HasFormula Then   ' can't do this for cells with formulas

      iStart = InStr(C.Value, "&")

      If iStart > 0 Then ' there is an &

        iEnd = InStr(iStart, C.Value, " ")

        C.Characters(iStart, iEnd - iStart).Font.ColorIndex = 2

      End If

    End If

  Next

End Sub

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-06-23T19:58:21+00:00

    Worked perfectly, just added it to my other module.

    Was this answer helpful?

    0 comments No comments