Excel VBA:删除单元格中的删除线字符 [英] Excel VBA: Delete strikethrough characters in a cell

查看:189
本文介绍了Excel VBA:删除单元格中的删除线字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大约有1000行数据.一些单元格由删除线和普通字符组成.我只想删除那些删除线字符,并在这些单元格中保留其他非删除线字符.单元的其余部分也应保持不变.

I have around 1000 rows of data. Some cells consist of both Strikethrough and normal characters. I would like to only delete those character that are Strikethrough and keeping the other non-Strikethrough character in those cells. The rest of the cell should also be left untouched.

单元格中的示例:

"334(删除线)124"

"334(strikethrough) 124"

代码应将单元格值更改为:

The code should change the cell value to:

"124"

不删除整个单元格.

推荐答案

Characters 中删除时,从右向左循环比较容易:

When deleting from Characters it's easier to loop right to left:

Sub Demo()
    Dim rng As Range, cl As Range
    Dim i As Long

    Set rng = [A1:A3] ' Get range of interest

    For Each cl In rng.Cells
    For i = Len(cl.Value) To 1 Step -1
        If cl.Characters(i, 1).Font.Strikethrough Then
            cl.Characters(i, 1).Delete
        End If
    Next i, cl

End Sub

这篇关于Excel VBA:删除单元格中的删除线字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆