我的东西尝试尝试:Excel VBA中使用函数和数组
没有与人的名单,我想做些什么,是读取数组单元值(这部分作品),比对工作表中的每个单元格执行检查,并且如果给定的单元格与数组中的字符串相同,则执行一些操作。
但不幸的是,我得到了“类型不匹配”的错误。
诗篇。我知道这没有多大意义,我可以在服务器功能里面找到一些东西,但是相信我,我有我的理由。 :-)
编辑:固定的几件事情,现在它看起来像这样(现在我得到的对象不支持方法的该属性)
如果有帮助,你也可以尝试一下。你只需要添加一个名为“服务器”的单元,然后在它下面写一些随机的单词。现在它应该在的msgbox “OK” x次,其中x是你写的行数写在细胞下,命名为 “服务器”
'server name
Function server(ByVal issrvname As String)
Dim j As Integer
Dim c As Range
Dim x As Integer, y As Integer
For Each c In Sheets("Topology").UsedRange.Cells
Dim srvname() As String
j = 0
If c.Cells.Value = "Servers" Then
y = c.Column: x = c.Row + 1
Do Until IsEmpty(Cells(x, y))
ReDim Preserve srvname(0 To j) As String
srvname(j) = Cells(x, y).Value
x = x + 1
j = j + 1
Loop
End If
Next c
For Each c In Sheets("Topology").UsedRange.Cells
If IsInArray(c.Cell.Value, srvname) Then
issrvname = True
Else
issrvname = False
End If
Next c
End Function
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function
Sub test()
Dim c As Range
For Each c In Sheets("Topology").UsedRange.Cells
If server(c) = True Then
MsgBox "ok"
End If
Next c
End Sub
请突出显示错误出现的行 – hnk
它现在显示出来,当我运行子测试()时出现msgbox说:运行时错误13:类型不匹配 – Divin3
“Do”后,添加“调试。打印x,y'。在'For Each cell'后面添加'Debug.Print cell.address'。这将缩小它的范围。然后,您可以在问题区域和单周期(F8)“停止”。请参阅http://www.cpearson.com/excel/DebuggingVBA.aspx – dcromley