热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何获取范围内的范围值-Howtogetthevalueofarangewithinarange

SoIneedtoextractinformationfromasheetwithonlycertainvalues.Fromabout550rowsdownto

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. Now I only see the rows which match to my criteria but how can I get the values of a specific range from?

所以我使用了autofilter。现在我只看到符合我标准的行,但是如何从中获取特定范围的值?

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

谢谢

2 个解决方案

#1


2  

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. It looks for the third visible row (not including the header row):

这是一个通过AutoFiltered表的A列循环的小例子。它查找第三个可见行(不包括标题行):

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

#2


2  

I think you need to choose if you want to get a specific cell like:

我认为您需要选择是否要获得特定的单元格,如:

Range("U10").Value

范围( “U10”)。价值

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.

一个完整的过滤和迭代代码。

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

推荐阅读
author-avatar
mou377
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有