2014-10-06 70 views
0

我有以下数组存储从搜索功能找到的值。如何使用.EntireRow传输数组?

If FoundCells Is Nothing Then 
    Debug.Print "Value Not Found" 
    Else 
    For Each FoundCell In FoundCells 
    Array1(i) = FoundCell.Value 'Instead of .Value I can use .Row but .EntireRow doesn't work 
    i = i + 1 
    Next FoundCell 
    j = i - 1 
    i = 1 
End If 

我然后提取使用转置其中工程关于“价值”和“.Row”阵列数据,但我不能从由“.EntireRow”各自发现值提取整行。

Range("A1:A" & UBound(Array1) + 1) = WorksheetFunction.Transpose(Array1) 

我试图用几种方式改变范围,但没有任何东西符合.EntireRow标准。从loannis评论后

更新:

如何使用EntireRow在我的数组移调根据存储在FoundCell搜索结果中的所有行到目标位置?

我用的FindAll搜索功能从cpearson http://www.cpearson.com/excel/findall.aspx

+0

这是一个典型的说明[XY问题](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。另外,您对以下答案的评论似乎是一个不同的问题。你想实现什么? – Ioannis 2014-10-06 18:10:37

+0

在我的问题中,我可能没有足够指出,我想根据存储在数组1中的多个搜索结果转置所有行。我将更新我的问题。 据我了解,我不能用魔法代码来做这件事。但也许我错了。 – CryoPeep 2014-10-06 18:49:59

回答

0

您可以提取一整行这样的但它是一个二维数组。

Sub MethodName() 
    Dim Array1 
    'Get all the cell values in row A 
    Array1 = Cells(1, 1).EntireRow 
    Dim i As Integer 
    'loop through the array and output the contents to the 2nd row 
    For i = 1 To UBound(Array1, 2) 
     Cells(2, i).Value = Array1(1, i) 
    Next i 
End Sub 
+0

感谢您的回答。我正在使用CPearson的FindAll功能 http://www.cpearson.com/excel/findall.aspx 我不确定如何在数组找到多个搜索结果时使用它。 – CryoPeep 2014-10-06 17:20:13

0

我得出的结论,对于这些我这样做的目的,我还不如报废的阵列做这样的:

If FoundCells Is Nothing Then 
    Debug.Print "Value Not Found" 
    Else 
    For Each FoundCell In FoundCells 
    FoundCell.EntireRow.Copy Worksheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1) 
    Next FoundCell 

End If