VBA:使用表格设置范围对象("表格名称")。行(1).Find

时间:2015-08-20 16:50:02

标签: excel vba excel-vba

我有一组看起来像这样的代码,我在第1行搜索特定的单词,并希望返回找到它的列号:

Dim MyRng As Range
Dim MySht As Worksheet
Set MySht = ThisWorkbook.Sheets("Numbers")
Set MyRng = MySht.Rows(1).Find("Header 3" etc...)
FindSeriesColumn = MyRng.Column 

似乎合乎逻辑的是,我应该能够消除定义工作表对象的需要,并且应该能够执行以下操作:

Dim MyRng As Range  
Set MyRng = ThisWorkbook.Sheets("Numbers").Rows(1).Find("Header 3" etc...)
FindSeriesColumn = MyRng.Column

但是,Set MyRng ...行会导致错误。使用ThisWorkbook.Sheets("Sheet Name").Rows(1).Find...的不当之处是什么?

1 个答案:

答案 0 :(得分:0)

使用此表格:

C:\Mono\lib\mono\4.5\Microsoft.CSharp.targets (CoreCompile target) ->
    CSC: error CS2011: Unable to open response file: C:\Program

enter image description here

修改#1:

定义要检查的范围更容易,并在该范围开始后启动 Find()

Sub fhksadf()
  Dim MyRng As Range
  Set MyRng = ThisWorkbook.Sheets("Numbers").Rows(1).Find(what:="Header 3")
  FindSeriesColumn = MyRng.Column
  MsgBox FindSeriesColumn
End Sub