Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 引用具有多个变量的单元格_Vba_Excel - Fatal编程技术网

Vba 引用具有多个变量的单元格

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

我分别定义了两个变量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" 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