excel - 如何在录制的宏中将单元格引用到替换代码中
问题描述
我正在尝试编写将职位标题列表转换为预定义标准职位的代码,这个IF
函数太大了。我想到的唯一方法是通过将“this”替换为“that”来记录宏,并对所有位置执行此操作,但如果可以在代码中引用单元格而不是文本字符串,则会容易得多:
What:="Field Installation Supervisor" (This part should be a cell reference from another sheet)
Replacement:= _ "Installation Supervisor" (This part is also a referenced cell from the same sheet as the above)
不知道是否可以在此替换代码中使用单元格引用
Sub replacing()
Sheets("Active Employees June 01 2019").Select
Cells.Replace What:="Field Installation Supervisor", Replacement:= _
"Installation Supervisor", LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
我希望使用参考单元来更轻松地更新/维护文件
解决方案
只需以正常方式引用单元格(无需选择工作表)。
Sheets("Active Employees June 01 2019").Cells.Replace _
What:=Sheets("this").Range("A1").Value, _
Replacement:=Sheets("this").Range("A2").Value, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
推荐阅读
- c# - 使用别名地址过滤用户 - MS Graph
- scala - sbt:依赖项目不先编译
- css - VS Code 中的美化:有没有办法对具有一个属性的样式使用单行格式,而对具有多个属性的样式使用多行格式?
- ruby-on-rails - 自定义过滤器到活动管理员以在索引页面上提取多行
- c++ - 使用快速选择的第 K 个最小元素
- c - C中的sscanf函数
- python - 镶嵌图像的 Python 循环问题
- java - 为字符串中的单词分配唯一的 int 值,然后将其存储到数组中
- android - 将此 LinearLayout 转换为 RelativeLayout 和 ConstraintLayout
- qt - MouseArea 调用 FileDialog :知道哪个元素打开了 FileDialog (QML)