Having a problem debugging using SendKeys

pglufkin

Board Regular
Joined
Jun 19, 2005
Messages
127
Hopefully this is something real simple that I am overlooking.

I need to eliminate a paragraph marker which is the last character at the end of my text in a cell within excel. In order to keep my formatting of text within a cell (different colors of text within the same string in the cell), i believe i must use SendKeys (I stand to be corrected on this). All other solutions I have tried to eliminate the end marker makes me lose my different colors in the paragraph I have formatted the text with. The SendKeys approach solves this problem. The SendKeys code I am using to eliminate the last character is:

Code:
Application.SendKeys "{F2}"
Application.SendKeys "{Backspace}"
Application.SendKeys "{Enter}"

Problem is, I am having to debug and when I come across these sendkey strokes in F8 step mode, it sends the strokes to the vbe and ceases processing them in the spreadsheet. How do I keep the sendkeys working on the spreadsheet while i am stepping through vbe debugging? thx
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Another reason for not using SendKeys. Try this instead, assuming the text is in cell A1:
Code:
Sub DLCC()
    Dim i As Integer
    With Range("A1")
        For i = 1 To .Characters.Count - 1
            .Characters(i, 1).Text = .Characters(i, 1).Text
            .Characters(i, 1).Font.Name = .Characters(i, 1).Font.Name
            .Characters(i, 1).Font.FontStyle = .Characters(i, 1).Font.FontStyle
            .Characters(i, 1).Font.Size = .Characters(i, 1).Font.Size
            .Characters(i, 1).Font.Strikethrough = .Characters(i, 1).Font.Strikethrough
            .Characters(i, 1).Font.Superscript = .Characters(i, 1).Font.Superscript
            .Characters(i, 1).Font.Subscript = .Characters(i, 1).Font.Subscript
            .Characters(i, 1).Font.OutlineFont = .Characters(i, 1).Font.OutlineFont
            .Characters(i, 1).Font.Shadow = .Characters(i, 1).Font.Shadow
            .Characters(i, 1).Font.Underline = .Characters(i, 1).Font.Underline
            .Characters(i, 1).Font.ColorIndex = .Characters(i, 1).Font.ColorIndex
        Next
        .Characters(i, 1).Text = ""     'delete last character in cell
    End With
End Sub
 
Upvote 0
Try this instead:
Code:
Sub DLCC2()
    
    With Range("A1")
        .Characters(.Characters.Count, 1).Text = ""     'delete last character in cell
    End With
    
End Sub
And for all populated cells on the active sheet:
Code:
Sub DLCC_All()
    
    Dim cell As Range
    
    Application.ScreenUpdating = False
    For Each cell In ActiveSheet.UsedRange
        If cell.Text <> "" Then cell.Characters(cell.Characters.Count, 1).Text = ""
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top