excel - 带有 VBA 的 Excel:引用工作表代码名称而不是选项卡名称
问题描述
因为我每周都会更新选项卡名称,而不是选项卡名称,所以我想使用 VBA 项目表名称(Sheet17),如果我更改选项卡名称,它不会更改。
我的代码是:
With ThisWorkbook.Sheets("update raw data")
Dim LastRow As Long
LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
Dim i As Integer
For i = 4 To LastRow
Cells(i, 56).Value = WorksheetFunction.Index(Sheet17.Range("O3:O300"),WorksheetFunction.Match(Cells(i,69).Value, Sheet17.Range("AB3:AB300"), 0))
Next i
End With
但它给了我这个错误:
'1004' -Unable to get the Match property of the WorksheetFunction class
解决方案
尝试这个..
Sub test()
Dim LastRow As Long, i As Integer
With ThisWorkbook.Sheets("update raw data")
LastRow = .Cells(.Rows.Count, 4).End(xlUp).Row
For i = 4 To LastRow
.Cells(i, 56) = WorksheetFunction.Index(Sheet17.[O3:O300], WorksheetFunction.Match(.Cells(i, 69), Sheet17.[AB3:AB300], 0))
Next i
End With
End Sub
推荐阅读
- c++ - 将派生类转换为基类时 dynamic_cast 失败
- angular - 如何解决:“无法解析 accueilComponent 的所有参数”
- php - 我的动态站点在站点在线时未加载,但在 localhost 中运行良好
- python - 如何绘制一天中的日期时间 - Matplotlib
- javascript - 如何使 PHP 版本的 Bitwise XOR 匹配 javascript 版本?
- asp.net - 终端中的命令“dotnet new mvc”但没有 mvc 模板
- applescript - 在选定的文本上运行 Applescript 并将其存储在剪贴板上
- java - 我们可以提高除 java 8 并行流以外的列表的性能吗
- python - 如何在 pyinstaller 中只包含需要的模块?
- c# - 如何在 C# 中将字节数组读取为多维数组?