在Excel

时间:2015-12-04 20:52:32

标签: excel-vba row hidden vba

我正在尝试根据一组过滤后的单元格的内容生成数据列表。首先(在代码中不包括),用户从列表框中选择一个标准,该标准将800个帐户的列表过滤到满足该标准的数量。从那里,我需要从Column a和对应于可见单元格的行中获取值。问题是我不能直接引用该行,因为当行被隐藏时,它不再是1,2,3,4等顺序列表。这是我的代码,我确切地知道我需要指定行的位置,而不是如何这样做

Sub AllProviders_Click()

Dim i As Integer
Dim vCount As Integer

vCount = Range("E18:E817").SpecialCells(xlCellTypeVisible).Count
MsgBox vCount 'for debugging


For i = 1 To vCount
    Sheets("Provider Output").Cells(3, 2 + i) = 'and this is where I have no idea
Next i
End Sub

当子运行时,可见的单元格数存储在vCount中,用于指定要填充的数据列数。我的问题是第7行,我需要指定要拉的单元格。

1 个答案:

答案 0 :(得分:1)

尝试:

Range("A18:A817").SpecialCells(xlCellTypeVisible).Copy _
  Sheets("Provider Output").Cells(3, 3)

编辑:如果那不适合你,那么可以尝试一下 -

Sub AllProviders_Click()

    Dim i As Integer
    Dim c As Range

    i = 1
    For Each c In Range("E18:E817").Cells
        If Not c.EntireRow.Hidden Then
            Sheets("Provider Output").Cells(3, 2 + i) = c.EntireRow.Cells(1).Value
            i = i + 1
        End If
    Next c
End Sub