excel - 使用 VBA 查找具有单独 EM 破折号的范围内的所有单元格并删除这些单元格
问题描述
我已经搜索了很长时间,但没有找到简单的方法来做到这一点。
我有一个包含正数和负数的表格以及大量带有单独的 Em 破折号(或等效项)的单元格,就像看起来像破折号的字符一样。
我想选择一个范围并删除所有此类单元格。
我想使用 Len(<2) 但仍然找不到使用 VBA 的简单方法。
嗨,为了替换某些类型的破折号,我使用了下面的代码。但我不知道如何只选择带有单独破折号的单元格。选择一个长度会找到单元格,但它可能不是一个完美的搜索方式。
Dim LastRow As Integer
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Range("B1:K" & LastRow).Select
Cells.Replace What:=ChrW(8722), Replacement:=Chr(45), lookat:=xlPart
Cells.Replace What:=Chr(150), Replacement:="", lookat:=xlPart
End Sub
谢谢
尼尔
解决方案
Sub RemoveDashes()
Dim m, r, cell As Object
Dim b As Boolean
Set m = Sheets("Sheet1").Range("B1")
Do
Set m = m.Offset(1, 0)
Set r = m.Resize(25, 1)
b = False
For Each cell In r
If cell.Value <> "" Then
b = True
End If
Next cell
'covers em, en, and hyphen:
If m.Value = "—" Or m.Value = "–" Or m.Value = "-" Then m.Value = ""
Loop Until b = False
End Sub
推荐阅读
- azure - Azure 应用服务:Web 服务器未能在指定时间内响应
- entity-framework - 如果数据库由专用项目管理,我如何在 appSettings 中配置我的连接字符串
- javascript - 如何在 next.config.js 中使用 next-images 和 rewrite
- kotlin - 注解处理时如何检查Element表示的类是指定类的子类型?
- php - 从第一个表中选择特定列,在 Laravel 中进行预加载
- python - popen.kill 不关闭浏览器窗口
- python - Django Rest api - 如何将多个表中的数据插入到单个表中
- npm - npm install code 1 错误 git dep 准备失败
- powershell - 卷曲到 Invoke-WebRequest
- rest - Apache Camel HTTP4 组件忽略 Date: Header