[英]How to get the value of a range within a range
So I need to extract information from a sheet with only certain values. 所以我需要从只有特定值的工作表中提取信息。 From about 550 rows down to 50 which are spread across the entire sheet.
从大约550行到50行分散在整个纸张上。
So I used autofilter for that. 所以我使用了autofilter。 Now I only see the rows which match to my criteria but how can I get the values of a specific range from?
现在我只看到符合我标准的行,但是如何从中获取特定范围的值?
This far I came: 到目前为止我来了:
I know that I have to use 我知道我必须使用
RangeINamed.SpecialCells(xlCellTypeVisible)
to work with only the visible information. 仅处理可见信息。 It worked for getting the starting and last row
它有助于获得起点和最后一行
startRow = bulkbatchRange.SpecialCells(xlCellTypeVisible).row
endRow = startRow + bulkbatchRange.SpecialCells(xlCellTypeVisible).rows.Count
But now I need to get the value of a specific column, I want to use a For loop so I can loop through all visible rows. 但是现在我需要获取特定列的值,我想使用For循环,这样我就可以循环遍历所有可见行。
So I tried to do 所以我试着去做
RangeINamed.SpecialCells(xlCellTypeVisible).range("U" & rowNumber).value
That didn't work it gave me nothing. 这没用,它什么都没给我。 Now I'm rather clueless so does someone maybe know how I get the value of that row in column U in RangeINamed?
现在我很无能,所以有人可能知道如何在RangeINamed中的U列中获得该行的值吗?
Thank you 谢谢
You can always retrieve the value in a specific cell like U10 with: 您始终可以使用以下命令检索U10等特定单元格中的值:
Range("U10").Value
whether the row is hidden or not. 该行是否隐藏。
EDIT#1 : 编辑#1 :
Here is a little example that loops down thru column A of an AutoFiltered table. 这是一个通过AutoFiltered表的A列循环的小例子。 It looks for the third visible row ( not including the header row ):
它查找第三个可见行( 不包括标题行 ):
Sub GoDownFilter()
Dim rLook As Range, r As Range
Set rLook = Intersect(ActiveSheet.UsedRange, Range("A:A").Cells.SpecialCells(xlCellTypeVisible))
rLook.Select
K = 0
For Each r In rLook
If K = 3 Then
r.Select
MsgBox "The third visible row has been selected"
Exit Sub
End If
K = K + 1
Next r
End Sub
I think you need to choose if you want to get a specific cell like: 我认为您需要选择是否要获得特定的单元格,如:
Range("U10").Value
Or a relative cell using something like 或者使用类似的东西的相对单元格
RangeINamed.SpecialCells(xlCellTypeVisible)(2,3).Value
Or 要么
RangeINamed.SpecialCells(xlCellTypeVisible)(2,3).Address 'To see if you are getting it right
EDIT: 编辑:
A complete code to Filter and Iterate. Filter和Iterate的完整代码。
Sub Filter()
Dim tableRange As Range, var, actualRow As Integer, lastRow As Integer
Set tableRange = Range("PUT_THE_TABLE_RANGE_HERE")
' Filter
With tableRange
Call .AutoFilter(5, "SPECIFIC_FILTER")
End With
Set f = tableRange.SpecialCells(xlCellTypeVisible)
With tableRange
Call .AutoFilter(5)
End With
For Each var In f.Cells.Rows
actualRow = var.Row
If actualRow <> 1 Then
' Do something
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.