将范围内的数据传输到数组,删除最后一行

我试图把工作表中的信息放入一个数组中,使用:

WBArray = ActiveSheet.Range(Cells(5, 1), Cells(end1, 29)).Value 

但有几个问题:首先,我的原始范围的最后2行包含无用的数据。 我怎么能删除这两行,因为我把它们传递给数组? 有没有像我正在使用的直接方法?

其次,我的范围从第5行开始,但由于它必须通过旧文件,这个数字可能会有所不同。 有没有办法我可以做一个浮动引用,所以它根据我想要的数据开始的地方变化? (例如,如果它从第7行开始)。

我已经试过循环每个项目,但是这似乎也没有工作。

有任何想法吗?

在OP的澄清后编辑

你可以使用这个function:

 Function GetArray(sht As Worksheet) ', uselessRows As Long) With sht GetArray = .Range(.Columns(1).Find(what:="Identifier", lookat:=xlWhole, LookIn:=xlValues), _ .Cells(.UsedRange.Rows(.UsedRange.Rows.Count).Row - 6, 29)).Value End With End Function 

并在您的主要子目录中调用它:

 WBArray = GetArray(mySht) 

其中mySht是任何有效的工作表引用,例如ActiveSheet

也许

  Sub x() Dim start1 As Long, end1 As Long, WBArray, r As Range With ActiveSheet Set r = .Columns(1).Find(What:="Identifier", After:=.Cells(.rows.Count,1), LookAt:=xlWhole, _ SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) If Not r Is Nothing Then start1 = r.Row end1 = .Range("A" & Rows.Count).End(xlUp).Row - 2 WBArray = .Range(Cells(start1, 1), Cells(end1, 29)).Value Else MsgBox "Identified not found" End If End With End Sub