Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
EXCEL VBA是否在数组中存储/保存整行?_Excel_Excel 2010_Vba - Fatal编程技术网

EXCEL VBA是否在数组中存储/保存整行?

EXCEL VBA是否在数组中存储/保存整行?,excel,excel-2010,vba,Excel,Excel 2010,Vba,已收到如何在列中搜索字符串,然后将其存储在数组中的帮助。可以存储整行吗?我已经找过了,但找不到 我想搜索一个包含字符串数据的工作表。然后将包含该字符串的行复制到另一个工作表中 我的代码看起来像这样 Set wsRaw = Worksheets("raw_list") Set phaseRange = wsRaw.Columns(PhaseCol) SearchString = "start" Set aCell = phaseRange.Find(What:=SearchString, Loo

已收到如何在列中搜索字符串,然后将其存储在数组中的帮助。可以存储整行吗?我已经找过了,但找不到

我想搜索一个包含字符串数据的工作表。然后将包含该字符串的行复制到另一个工作表中

我的代码看起来像这样

Set wsRaw = Worksheets("raw_list")
Set phaseRange = wsRaw.Columns(PhaseCol)

SearchString = "start"
Set aCell = phaseRange.Find(What:=SearchString, LookIn:=xlValues, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
    Set bCell = aCell
    ReDim Preserve arrStart(nS)
    arrStart(nS) = aCell.Row
    nS = nS + 1
    Do While ExitLoop = False
        Set aCell = phaseRange.FindNext(After:=aCell)
        If Not aCell Is Nothing Then
            If aCell.Row = bCell.Row Then Exit Do
            ReDim Preserve arrStart(nS)
            arrStart(nS) = aCell.Row
            nS = nS + 1
        Else
            ExitLoop = True
        End If
    Loop
Else
End If

感谢您的帮助:)

由于您正在根据相关列中的搜索条件将数据从Sheet1复制到Sheet2,因此我建议使用自动筛选

看到这个了吗

Sub Sample()
    Dim wsRaw As Worksheet
    Dim strSearch As String
    Dim PhaseCol As Long, LastRow As Long
    Dim phaseRange As Range, rng As Range

    strSearch = "start"

    '~~> Change this to the relevant column
    PhaseCol = 1

    Set wsRaw = Sheets("raw_list")

    With wsRaw
        LastRow = .Range(Split(Cells(, PhaseCol).Address, "$")(1) & _
                  .Rows.Count).End(xlUp).Row

        Set phaseRange = wsRaw.Range( _
                                    Split(Cells(, PhaseCol).Address, "$")(1) & _
                                    "1:" & _
                                    Split(Cells(, PhaseCol).Address, "$")(1) & _
                                    LastRow)

        '~~> Remove any filters
        .AutoFilterMode = False

        '~~> Filter, offset(to exclude headers) and copy visible rows
        With phaseRange
            .AutoFilter Field:=1, Criteria1:=strSearch
            Set rng = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
            '~~> Chnage Sheet2 to the relevant sheet name where you want to copy
            rng.Copy Sheets("Sheet2").Rows(1)
        End With

        '~~> Remove any filters
        .AutoFilterMode = False
    End With
End Sub
快照


在上面的代码中,您存储的是找到匹配项的行号。为什么要将整行内容存储在数组中。你到底想实现什么?在一张纸上,我有这些处于不同阶段的“案例”。每箱一排。所以我想要实现的是搜索该表中的某个阶段,然后如果可能的话,将该阶段中的案例存储在一个数组中,以便稍后调用它们。对不起,我的英语不好,没有告诉你我的意思。在这种情况下,你不需要存储整行:)你可以像现在这样存储行号,然后稍后再从行号中检索行详细信息。我将使用哪个函数来执行此操作?再次感谢您的快速回复。要检索行数据,您可以使用此
Sheets(“Sheet1”)。行(arrStart(i))
感谢您的回答。但是假设我会继续使用我的数组。是否可以检查已搜索的行,然后将某些列复制到另一个工作表中?是:)
Sheets(“Sheet1”)。行(arrst(i))。复制工作表(“Sheet2”)。行(r)
我感觉我做错了什么:)我已成功地在不同的工作表中写出数组。但当我尝试复制行时,只会显示最后一行<代码>代码i=1到1000页(“原始列表”)。行(arrStart(i))。复制表(“数据表”)。行(r)表(“数据表”)。选择范围(“A1”)。选择活动表。粘贴应用程序。CutCopyMode=False下一步没关系:)我发现哪里做错了。非常感谢你的帮助