Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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,编辑: 现在我将数组更改为range:Set arrDeviceType=ScriptSheet.range(“P2:p”&LastApar) 但是我仍然在arrDeviceType(X,1).Resize(I-2,0)=“Internet” 我的VBA脚本对此行有问题 arrDeviceType(X, 1).Resize(I - 2, 0) = "Internet" arrDeviceType设置为一个变量,它的单元格值为“Internet系统”,我需要将带有“Internet系统”的列与

编辑:

现在我将数组更改为range:
Set arrDeviceType=ScriptSheet.range(“P2:p”&LastApar)
但是我仍然在
arrDeviceType(X,1).Resize(I-2,0)=“Internet”


我的VBA脚本对此行有问题

arrDeviceType(X, 1).Resize(I - 2, 0) = "Internet"
arrDeviceType设置为一个变量,它的单元格值为“Internet系统”,我需要将带有“Internet系统”的列与另一个带有“Internet”的工作表列进行比较,但它们的含义相同。因为我需要匹配这两个值,所以我想让脚本首先在一个工作表中识别“Internet系统”与“Internet”相同,而不需要对工作表进行实际更改。因此,我将列中的所有内容存储到arrDeviceType
arrDeviceType=ScriptSheet.Range(“P2:P”和LastApar.Value
)中

所以问题是我应该怎么做?我对一个日期值也做了同样的操作,将其更改为一个月的第一天,像这样
arrOpenDate(X,1)=arrOpenDate(X,1)-day(arrOpenDate(X,1))+1
,它可以工作,所以我尝试用这个字符串值实现相同的操作

下面发布了相关代码,需要匹配三对字符串:

    I = 1
    X = 1
    Do While arrDeviceType(I, 1) = "Internet System"
    I = I + 1
    Loop
    arrDeviceType(X, 1).Resize(I - 2, 0) = "Internet"
    X = I
    OPS = X
    Do While arrDeviceType(OPS, 1) = "Other production system"
    OPS = OPS + 1
    Loop

    arrDeviceType(X, 1).Resize(OPS - X, 0) = "DR"
    X = OPS
    DR = X
    Do While arrDeviceType(DR, 1) = "System subject to disaster recovery"
    DR = DR + 1
    Loop
    arrDeviceType(X, 1).Resize(DR - X, 0) = "DR"

arrDeviceType
是否包含范围或范围的值?@GSerg它包含的值范围为
arrDeviceType=ScriptSheet.range(“P2:P”&LastApar)。Value
,值也是字符串。如果它包含变量数组,则它没有
Resize
方法,也不能在一次分配操作中分配多个数组成员。所有这些功能都是由
范围
提供的,如果需要,请存储
范围
。@GSerg但如果我将其更改为
范围
,工作表中的实际值会更改吗?是的。此外,如果不将其更改为范围,则工作表上的实际值不会更改。
arrDeviceType
是否包含范围或范围的值?@GSerg它包含的值范围为
arrDeviceType=ScriptSheet.Range(“P2:P”&LastApar”)。值
,值也是字符串。如果它包含变量数组,它没有调整大小的方法,也不能在一次分配操作中分配多个数组成员。所有这些功能都是由
范围
提供的,如果需要,请存储
范围
。@GSerg但如果我将其更改为
范围
,工作表中的实际值会更改吗?是的。此外,如果不将其更改为范围,则工作表上的实际值不会更改。