计算B3中的范围(行)开始

时间:2019-05-03 20:04:15

标签: excel vba

我有从B3开始并且是动态的数据,因此它的范围可能是5行到500。我想遍历该范围内的行数。

这是用于查询已检入报告数量的数据。

Dim range1 As Range

Set range1 = Sheet1.Range("B3 : B" & Cells(Rows.Count)).End(xlUp).Rows

结果应为范围B3:B46或任何结束行号。

4 个答案:

答案 0 :(得分:0)

尝试一下:

 Dim cell As Range

    For Each cell In Sheet1.Range("B3:B" & Sheet1.Cells(Sheet1.Rows.count, 2).End(xlUp).Row)
        'Do your stuff
    Next cell

答案 1 :(得分:0)

尝试一下

Dim range1 As Range
Dim x as long

With Sheet1
    x= .Cells(.rows.Count, 2).End(xlUp).Row
    Set range1 = .Range("B3", .Cells(x,2))
End with

答案 2 :(得分:0)

另一种方法可以使最后一行包含数据:

Option Explicit
Sub RowCount()

    Dim WS As Worksheet
    Dim lrow As Long

    Set WS = ActiveSheet

    With WS
        lrow = .Range("B" & .Rows.Count).End(xlUp).Row - 2
    End With
End Sub

答案 3 :(得分:0)

最简单的方法是使用$('#txtSearch').keypress(function (event) { debugger; var keycode = (event.keyCode ? event.keyCode : event.which); if (keycode == '13') { var strUrl = '/stocklist/All%20Categories-All%20Makers-All%20Models-0-0-' + $('#txtSearch').val(); location.href = strUrl; return false; } }); 属性。

.End(xlUp)

现在您已将Dim rng as Range: Set rng = Sheet1.Range("B3:B" & Sheet1.Cells(Rows.Count, 2).End(xlUp).Row) 存储在变量B3:B<last_row>