excel - VBA - 代码上的参数不是可选错误
问题描述
我想编写一个 VBA 代码来检查单元格是否有图像,以及它是否在与图像相同的行中打印一些东西(可能是任何东西,在这种情况下我选择了数字 1),在第 6 列。
我在子的第一行不断收到“Argument not Optional”错误。好奇是否有人可以帮助我!谢谢!!
Function CellImageCheck(CellToCheck As Range) As Integer
' Return 1 if image exists in cell, 0 if not
Dim wShape As Shape
For Each wShape In ActiveSheet.Shapes
If wShape.TopLeftCell = CellToCheck Then
CellImageCheck = 1
Else
CellImageCheck = 0
End If
Next wShape
End Function
Sub testFunction()
Dim i As Integer
Application.ScreenUpdating = False
For i = 3 To 10 Step 1
If CellImageCheck(Cells(i, 1)) Then
Cells(i, 6) = CellImageCheck
Else
End If
Next i
End Sub
解决方案
根据我的评论:
Function CellImageCheck(CellToCheck As Range) As Boolean
' Return True if image exists in cell, False if not
CellImageCheck = False
Dim wShape As Shape
For Each wShape In ActiveSheet.Shapes
If wShape.TopLeftCell.Address = CellToCheck.Address Then
CellImageCheck = True
Exit For
End If
Next wShape
End Function
Sub testFunction()
Application.ScreenUpdating = False
With Worksheets("Sheet1") 'Change this to the sheet being tested.
Dim i As Long
For i = 3 To 10 Step 1
Dim bl As Boolean
bl = False
bl = CellImageCheck(.Cells(i, 1))
If bl Then .Cells(i, 6) = bl
Next i
End With
End Sub
推荐阅读
- javascript - mongodb find 方法可以带动态查询吗?
- c++ - 具有多态性的 C++ Final 类
- python - 有什么方法可以改变从 pyqtgraph 导出的图像质量?
- pdf - 在保留页面大小的同时裁剪 pdf 内容(图像)
- assembly - 汇编语言:编写一个通用程序来纠正字符串中的多余字符
- flutter - Flutter Client Grpc:Protoc-gen-dart:找不到程序
- reactjs - React Native 中的旋转图像按钮
- java - Android 无法以编程方式连接到 WIFI
- html - 用 flex 填充父级的高度
- javascript - 当我尝试使用 emailjs 时出现 thsi 错误:Uncaught ReferenceError: sendMail is not defined emailjs