Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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
Vba 循环行范围-如何获取特定单元格?_Vba_Excel_Loops_Excel 2007 - Fatal编程技术网

Vba 循环行范围-如何获取特定单元格?

Vba 循环行范围-如何获取特定单元格?,vba,excel,loops,excel-2007,Vba,Excel,Loops,Excel 2007,嗨,我正试图得到一个特定的细胞与上述循环。我认为rowIndex是.Cells(行,列)上的行数;但事实似乎并非如此。我正在尝试使用过滤器循环数据。 有人能帮我吗? 提前谢谢 您处理的是一行,因此,如果直接处理rowIndex,则任何单元格(行、列)引用都应为1,如果引用工作表上的单元格,则应为rowIndex.row With Worksheets("Tripdata") For filtercount = 1 To 1 Worksheets("Tripdata").R

嗨,我正试图得到一个特定的细胞与上述循环。我认为rowIndex是.Cells(行,列)上的行数;但事实似乎并非如此。我正在尝试使用过滤器循环数据。
有人能帮我吗?

提前谢谢

您处理的是一行,因此,如果直接处理rowIndex,则任何单元格(行、列)引用都应为1,如果引用工作表上的单元格,则应为rowIndex.row

With Worksheets("Tripdata")
    For filtercount = 1 To 1
        Worksheets("Tripdata").Range("A1").AutoFilter Field:=4, Criteria1:=stationidentify(filtercount, 1)
        For Each rowIndex In .UsedRange.Rows
            If (rowIndex.Hidden) Then
            'nothing
            Else
                If (firstpass) Then
                    firstpass = False
                Else
                    MsgBox rowIndex(2, 2)
                    test = test + 1
                    Dim currentstat As Double, finalstat As Double
                    currentstat = Worksheets("Tripdata").Cells(rowIndex, 3).Value
                    finalstat = Worksheets("Tripdata").Cells(rowIndex, 7).Value

我不明白
MsgBox行索引(2,2)
。为什么要将当前行索引中的单元格下移一行并放在B列中?@Jeeped我目前正试图通过编写一堆东西来理解rowIndex实际上得到了什么。那是错误的。我的问题是不知道如何使用for each循环访问该行上的单元格。
for filtercount=1到1
?而且,
(firstpass)
应该是
filterpass
,我想现在我明白了。这个词的使用使我感到困惑。非常感谢。我希望我没有理解rowIndex(1,2)和rowIndex.Cells(1,2)之间的区别。没有区别。前者是后者的简写,省略了默认属性.cells。它工作得非常好。正在尝试为调度优化编写代码。我不熟悉VBA语法。非常感谢您的帮助。顺便说一句,
工作表(“Tripdata”).Range(“A1”).AutoFilter
可能只是
.Range(“A1”).AutoFilter
,因为它位于带。。。最后也是块。
'put these outside the loop
Dim currentstat As Double, finalstat As Double
For Each rowIndex In .UsedRange.Rows
...
Else
    MsgBox rowIndex(1, 2)  'column B value within rowIndex
    MsgBox rowIndex.cells(1, 2)  'column B value within rowIndex
    test = test + 1
    currentstat = Worksheets("Tripdata").Cells(rowIndex.row, 3).Value
    finalstat = Worksheets("Tripdata").Cells(rowIndex.row, 7).Value
    'you're inside a With ... End With block so these are the same
    currentstat = .Cells(rowIndex.row, 3).Value  'column C value within rowIndex
    finalstat = .Cells(rowIndex.row, 7).Value  'column G value within rowIndex
    debug.print currentstat
    debug.print finalstat