我的東西嘗試嘗試: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