excel - 为什么缺少对象变量或 With-block 变量?
问题描述
为什么有一个
缺少对象变量或 With-bock 变量
如果我能在互联网上找到任何东西,我已经用谷歌搜索了,但我没有
Sub One_Find()
Dim FieldRange As Range
Dim FirstAddress As String
FieldRange = Cells.Find(What:=ActiveCell.Value, LookIn:=xlValues, LookAt:=xlWhole)
FirstAddress = FieldRange.Address
Do
FieldRange = Cells.FindNext(FieldRange)
Loop While FieldRange.Address <> FirstAddress
FieldRange.Value = "WORKS"
End Sub
解决方案
一些一般规则:
确保您的代码包含您要使用的工作簿和工作表。这可以通过使用
With Statement
With ThisWorkbook.Worksheets("Sheet1") End With
避免
ActiveCell
使用单元格地址引用单元格。在使用之前,请
FieldRange
确保检查它是否Nothing
存在。If FieldRange Is Nothing Then Debug.Print "Value was not found." Else Debug.Print "Value found in :" & FieldRange.Address End If
一种
Do … While
结构Do While i < 5 i = i + 1 MsgBox "The value of i is : " & i Loop
推荐阅读
- sqlite - 为什么有时我在列中得到最后一个变量,有时在列中得到所有不同的变量?
- javascript - 如何在javascript中使用三元运算符根据长度将变量设置为true或false?
- reactjs - 如何在课堂反应中从外部触发功能
- wordpress - 请检查我的代码如何为我的新自定义帖子类型创建单独的类别
- swift - 如何在swift中禁用键盘的返回键?
- node.js - AWS Lambda & Node:使用流将数据从 S3 发送到客户端
- c++ - 链表在开头和结尾插入
- awk - 获取唯一的字符串出现并显示它
- java - 如何以编程方式打开启用编辑的 Eclipse 比较编辑器?
- django - Django admin list filter 根据两个字段计算字段