vba - 引用具有多个变量的单元格
问题描述
我分别定义了 2 个变量字符串和整数。使用需要的变量来引用单元格并提取数据。有人可以帮忙吗?
With Page 3
.activate
Dim OracleProjType as String -> stores the value "C"
Dim SearchProjNameRow as Integer -> Stores the value "6"
Dim OracleProjTypeData as string -> Stores the data of "C6" cell
OracleProjTypeData = .Range(" " & OracleProjType & ":" & SearchProjNameRow).Value -> Getting an error here as "Run time error 1004, Application - Object defined error"
End with
解决方案
尝试
Option Explicit
Public Sub TEST()
Dim OracleProjType As String
Dim SearchProjNameRow As Long
Dim OracleProjTypeData As String
OracleProjType = "C" '<==Assign the value to the variable
SearchProjNameRow = 6
With Worksheets("Sheet3") '<== Work with that sheet using with so no activate
OracleProjTypeData = .Range(OracleProjType & SearchProjNameRow).Value '<==Concatenate values to create range reference
Debug.Print OracleProjTypeData
End With
End Sub
推荐阅读
- xslt - xslt 1.0 将 xs:date 转换为特定的 dateFormat DD-MON-YYYY
- ruby-on-rails - Rails:使用 RestClient 的外部 API 集成(未定义的局部变量或方法“用户”)
- google-sheets - 如何在 SUM() 之前应用公式?
- arrays - 将 postgresql jsonb 值转换为 int 数组并从中删除元素
- javascript - 动态添加行并运行脚本
- python - python3.6和python3.7的导入差异
- xamarin - BarTintColor 不适用于 Xamarin 的 iOS 13 中的 PrefersLargeTitles
- rest - 保护一个应用程序使用的公共 REST API
- github - 创建 git pre-receive 挂钩以将 git 提交与 jira id 链接
- listview - Flutter ListView 不断执行future函数