Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.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,我想访问代码中的工作表。我要访问的工作表的名称存储在另一个工作表(SheetA)中。根据用户在SheetA中输入的内容,我要访问的工作表会发生变化。因此,我将要使用的工作表的名称(从工作表A检索)存储在字符串中 如何使用变量字符串作为名称来调用所需的工作表?以下是我的代码: Dim temp As String sheetName = .Cells(counter, 3)' this is a cell in Sheet A containing the na

我想访问代码中的工作表。我要访问的工作表的名称存储在另一个工作表(SheetA)中。根据用户在SheetA中输入的内容,我要访问的工作表会发生变化。因此,我将要使用的工作表的名称(从工作表A检索)存储在字符串中

如何使用变量字符串作为名称来调用所需的工作表?以下是我的代码:

         Dim temp As String
         sheetName = .Cells(counter, 3)' this is a cell in Sheet A containing the name of my next sheet

         With Sheets(sheetName) 'ERROR HERE ************
          Do While valueT(counter + 1) > .Cells(counter4, 1)   
            colletM(counter) = .Cells(counter4, 1)
            counter4 = counter4 + 1
          Loop
         End With

考虑将所有工作表名称按顺序排列在一个数组中,将我想要作为工作表名称的字符串(节奏)与数组中的工作表名称进行比较,并选择我需要的工作表索引,但您也可以建议一种更好的方法。

您的代码适合我,我能看到错误的唯一原因是变量sheetName中的工作表名称在此工作簿中不存在