我想要一个函数来返回给定 rowIndex 和单元格值的列的索引:
'Get index of column given a heading name
Function FindColumnIndex(name As String, rowNumber As Integer) As Integer
Dim index As Integer
index = 1
Dim found As Boolean
found = False
Do While found = False
If Cells(rowNumber, index).Value = name Then
FindColumnIndex = index
Exit Do
End If
index = index + 1
Loop
FindColumnIndex = index
End Function
然后,我将其分配给一个值:
Dim colIndex As Integer
colIndex = FindColumnIndex("Physical or Virtual", 2)
问题是这不起作用-我确定我的功能不正确-有人知道我做错了什么吗?