Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel VBA - Delete Single Character from Cell without losing formatting of remainder of cell contents
    primarykey
    data
    text
    <p>I am trying to delete the first occurrence of "&lt;" and ">" in a cell without losing formatting of the remainder of the cell's contents.</p> <p>I have looked in several places here, and other, to no avail.</p> <p>This is what I am trying to do:</p> <p>Say "A1" contains the text:</p> <pre><code>"This is &lt;a&gt; long string with several &lt;occurrences&gt; of a &lt;special&gt; character." </code></pre> <p>In any case, What I am trying to do is remove the ">", and in a perfect world the "&lt;", from the first word which contains them while maintaining the bold formatting as well as the "&lt;" and ">" on the next word containing them.</p> <p>This is ONLY other code executing prior to the code I am having issues with.</p> <pre><code>inTx = Range("A2").Value outTx = Replace(inTx, "Init_Day", Range("A3").Value) Range("A2").Value = outTx </code></pre> <p>Which replaces the <code>&lt;placeholder&gt;</code> text with the actual text, a two digit number in this case.</p> <p>Here is the code that is not working for me:</p> <pre><code>SearchString = Range("A2").Value Char1 = "&lt;" Char2 = "&gt;" For i = 1 To Len(SearchString) If Mid(SearchString, i, 1) = Char1 Then startPos = i Exit For End If Next i For i = 1 To Len(SearchString) If Mid(SearchString, i, 1) = Char2 Then endPos = i Exit For End If Next i Range("A2").Characters(startPos, endPos - startPos).Font.Bold = True Range("A2").Characters(startPos - 1, 1).Delete </code></pre> <p>All code works fine until I reach the last line:</p> <pre><code>Range("A2").Characters(startPos - 1, 1).Delete </code></pre> <p>then nothing happens.</p> <p>I've even tried:</p> <pre><code>Range("A2").Characters(startPos - 1, 20).Delete </code></pre> <p>Still nothing...</p> <p>I know this should be easy but I can't seem to figure it out.</p> <p>Thanks in advance.</p>
    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.
 

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