Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a slightly different approach to Chris's. I remove all the non-break spaces before searching for <code>space space</code>.</p> <p>Your problem is that your strings contain non-break spaces. Space is code 32. Non-break space is code 160. You cannot find <code>space space</code> because your strings do not contain <code>space space</code>. </p> <p>Try the following:</p> <pre><code>Sub DeleteAfterDoubleSpace() Dim Pos As Integer Dim Rng As Range With Sheets("xxxxx") ' Replace any non-break spaces .Cells.Replace What:=Chr(160), Replacement:=" ", LookAt:=xlPart ' Find the first cell containing double space, if any Set Rng = .Cells.Find(" ", .Range("A1"), xlValues, xlPart, xlByRows, xlNext) Do While True If Rng Is Nothing Then ' All double spaces removed, exit. Exit Do End If Pos = InStr(Rng.Value, " ") ' Find position of double space within cell ' Extract first Pos-1 characters from cell and set cell to those characters. Rng.Value = Mid(Rng.Characters, 1, Pos - 1) Set Rng = .Cells.FindNext(Rng) ' Find the next double space Loop End With End Sub </code></pre> <p><strong>P.S.</strong></p> <p>I discovered the non-break spaces by pasting your strings to cell A1 of a worksheet and calling the following routine so:</p> <pre><code>Call DsplDiag(Range("A1") </code></pre> <p>The output for the first string is:</p> <pre><code> T h e A p p l e s a r e G r e e n   T h e 54 68 65 20 41 70 70 6C 65 73 20 61 72 65 20 47 72 65 65 6E 20 A0 54 68 65 y a r e s u p p l i e d b y J o h n   79 20 61 72 65 20 73 75 70 70 6C 69 65 64 20 62 79 20 4A 6F 68 6E A0 </code></pre> <p>Notice the two A0's after Green and at the end. A0 is hexadecimal for 160.</p> <pre><code>Sub DsplDiag(DsplStg As String) ' Output the string DsplStg to the immediate window in both display and ' hexadecimal formats Dim CharChar As String Dim CharInt As Integer Dim CharStg As String Dim CharWidth As Integer Dim HexStg As String Dim Pos As Integer Dim Printable As Boolean CharStg = "" HexStg = "" For Pos = 1 To Len(DsplStg) CharChar = Mid(DsplStg, Pos, 1) CharInt = AscW(CharChar) Printable = True If CharInt &gt; 255 Then CharWidth = 4 ' Assume Unicode character is Printable Else CharWidth = 2 If CharInt &gt;= 32 And CharInt &lt;&gt; 127 Then Else Printable = False End If End If HexStg = HexStg &amp; " " &amp; Right(String(CharWidth, "0") &amp; _ Hex(CharInt), CharWidth) If Printable Then CharStg = CharStg &amp; Space(CharWidth) &amp; CharChar Else CharStg = CharStg &amp; Space(CharWidth + 1) End If If Pos Mod 25 = 0 Then Debug.Print CharStg Debug.Print HexStg Debug.Print CharStg = "" HexStg = "" End If Next Debug.Print CharStg Debug.Print HexStg End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload