excel - 查找并替换“=”为“=”直到最后一个工作表
问题描述
我正在使用根据字体颜色对值求和的代码。它工作得很好,但由于某种原因,所有方程都会随机变为#N/A,然后我必须进行查找并将“=”替换为“=”以恢复总和。我与我的主管共享文件,我想找到一种方法来防止#N/A 替换公式,或者有一个代码允许我创建一个按钮来运行查找和替换以恢复总和。当我使用查找和替换代码时,它会无限循环。有没有办法让它在最后一个工作表上结束?或者一次只浏览工作簿一次。
这是我正在使用的总和代码:
Function SumCellsByFontColor(rData As Range, cellRefColor As Range)
Dim indRefColor As Long
Dim cellCurrent As Range
Dim sumRes
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.Volatile
sumRes = 0
indRefColor = cellRefColor.Cells(1, 1).Font.Color
For Each cellCurrent In rData
If indRefColor = cellCurrent.Font.Color Then
sumRes = WorksheetFunction.Sum(cellCurrent, sumRes)
End If
Next cellCurrent
SumCellsByFontColor = sumRes
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Function
Sub Sumcellsbyfont()
End Sub
这是我一直在尝试的查找和替换代码:
Sub FindReplaceAll()
Dim sht As Worksheet
Dim fnd As Variant
Dim rplc As Variant
fnd = "="
rplc = "="
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace what:=fnd, Replacement:=rplc, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
End Sub
我是使用 VBA 的新手,但我希望通过字体颜色求和来完成这项工作,这样可以省去在进行更改时必须从常规求和公式中排除值的麻烦。我正在使用每个工作簿大约 15 张纸。
非常感谢任何帮助。
解决方案
推荐阅读
- android - 如何从 firebase 获取多个密钥
- ruby-on-rails - 如何在 ruby on rails 中将日期格式从 dd-mmm-yyyy 转换为 yyyy-mm-dd
- java - 如何在多线程线程中传递上下文
- algorithm - 从给定的字符串生成一组唯一的数字/字符串
- python - 如何将 df 中的列转换为具有日期时间格式的纪元,反之亦然?
- javascript - Service Worker 在本地工作,但在托管我的网站后未注册
- sql - SQL 查询需要时间执行
- javascript - 从 json 获取图像位置
- elixir - Elixir 应用程序中的多个主管
- kubernetes - tcp 10.0.2.15:6443:getsockopt:Debian 9 VM 上的连接被拒绝