Vba 引用具有多个变量的单元格
我分别定义了两个变量string和integer。使用需要的变量引用单元格并提取数据。有人能帮忙吗Vba 引用具有多个变量的单元格,vba,excel,Vba,Excel,我分别定义了两个变量string和integer。使用需要的变量引用单元格并提取数据。有人能帮忙吗 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
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
试一试
选项显式
公共子测试()
Dim OracleProjType作为字符串
模糊搜索PROJNAMEROW尽可能长
Dim OracleProjTypeData作为字符串
OracleProjType=“C”'为什么“C:6”
是一个有效范围?
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