【问题标题】:VBA Resizing a Current Region to omit bottom rowVBA 调整当前区域的大小以省略底行
【发布时间】:2021-08-27 10:18:54
【问题描述】:

我使用下面的代码对.CurrentRegion 进行数字排序。然而,这个范围的底行是 SubTotal,因此我不希望它包含在排序中,并且在排序发生后它必须保持底行。我正在努力在排序之前调整 .CurrentRegion 的大小以不包括底行。

我已尝试调整它的大小,但您似乎无法调整 CurrentRegion 的大小?这是我尝试过的:With .Cells(rw, 7).CurrentRegion.Resize(-1, 0)

Dim j As Long, rw As Long
   rw = 1
   With Worksheets("Export_Bets")
        Do While rw < .Cells(Rows.Count, "A").End(xlUp).Row
            With .Cells(rw, 7).CurrentRegion
               With .Resize(.Rows.Count, 2)
                    .Cells.Sort Key1:=.Columns(2), Order1:=xlDescending, _
                                Key2:=.Columns(1), Order2:=xlAscending, _
                               Orientation:=xlTopToBottom, Header:=xlNo

【问题讨论】:

    标签: excel vba sorting


    【解决方案1】:

    RowSize 属性表示行数,而 NOT 在您使用时表示行数的变化。

    所以你需要类似的东西

    With Cells(rw, 7).CurrentRegion.resize(rowsize:=Cells(rw,7).CurrentRegion.Rows.Count - 1)
    

        With Cells(rw,7).CurrentRegion
            With .resize(rowsize:=.Rows.Count - 1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-06
      • 2011-11-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多