我有一大堆代码可以正常工作:
Function sshProblem(rng As Range) As Boolean
Dim portStatus As String
portStatus = rng.Value
Dim deviceType As String
deviceType = Cells(Application.Caller.Row, 3).Value
Dim sshDevices As Variant
sshDevices = Array("linux", "vmw", "docker", "unix")
If StrComp(portStatus, "No") = 0 Then
sshProblem = Not IsError(Application.Match(deviceType, sshDevices, 0))
End If
End Function
现在代码需要扩展,而不是在sshDevices数组中存储值,这些值需要驻留在另一个工作表的列中,所以我试图替换
sshDevices = Array("linux", "vmw", "docker", "unix")
与
sshDevices = Worksheets("Config sheet").Range("I2:I11").Value
此时条件格式化已停止工作。我如何从单元格范围中获取值并将它们插入变量中进行比较?
答案 0 :(得分:0)
我不是百分百肯定你要用你的代码实现的目标,而是回答你的问题
如何从单元格区域中获取值并将它们插入变量中进行比较?
您可以使用For Each
循环,类似于:
dim myCell as range, myRange as range
set myRange = Worksheets("Config sheet").Range("I2:I11")
For Each myCell in myRange
sshDevice = myCell.Value
'do stuff you need with sshDevice
Next myCell
如果你想保留sshDevices数组,你可以这样做,并使用For Each
循环单独添加每个项目。
dim counter as int
counter = 0
For Each myCell in myRange
sshDevice(counter) = myCell.Value
counter = counter + 1
next myCell
答案 1 :(得分:0)
使用
Option Base
只是被告知这样你就会有一个基于 1的数组,无论Array()
如何影响返回的数组形式<?xml version="1.0" encoding="UTF-8"?>
<Configuration package="log4j.test" status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="log4j.test.Log4jTest" level="debug">
<AppenderRef ref="Console"/>
</Logger>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
函数