我使用这些代码行在我的VBScript中查找特定单元格。
Set FoundCell = objSheetSrc.Range("A1:BZ1").Find("Device", , , 1)
For Each Cell In Range()
If Cell.Value <> "*MSP430*" Then
Cell.EntireRow.Delete
End If
Next
因此,您可以看到Range()是我遇到问题的地方。基本上,我需要弄清楚如何选择FoundCell所在的整个列作为范围,然后删除不包含&#34; MSP430&#34;的行。
有什么想法吗?
谢谢,
安德鲁
答案 0 :(得分:3)
编辑 - 适用于VBScript
试试这个:
Dim rngDel
Set FoundCell = objSheetSrc.Range("A1:BZ1").Find("Device", , , 1)
For Each Cell In objSheetSrc.Range(FoundCell.offset(1,0), _
objSheetSrc.cells(objSheetSrc.Rows.Count, _
FoundCell.column).End(-4162)).Cells ' -4162=xlUp
If Cell.Value <> "*MSP430*" Then
If rngDel is Nothing Then
Set rngDel=cell
Else
Set rngDel = xlApp.Union(cell,rngDel) 'xlApp = your Excel reference
End If
End If
Next
If Not rngDel Is Nothing Then
rngDel.EntireRow.Delete
End If