即使启用了“自动筛选”,也会在电子表格中获取最后一行 [英] Getting last row on spreadsheet even if Auto Filter is on

查看:191
本文介绍了即使启用了“自动筛选”,也会在电子表格中获取最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个跨越20列的数据转储,已经应用了自动过滤器,数据范围中的最后一行是空白的17列和3列都有公式。 我们的想法是,最终用户完成一个表单,该表单将
表单数据发送到数据范围中最后一行的17列,我的宏将这些公式拖到下一行。


我遇到的问题是我正在尝试使用下面的代码确定数据范围中的最后一行,但如果正在应用自动过滤器,则不会返回最后一行数据范围但返回最后一个过滤的行+ 1.如何在不停用自动过滤器的情况下返回
数据返回的最后一行?


nextRow = ActiveSheet.Cells(Rows。计数,"A")。结束(xlUp)。行+ 1


非常感谢帮助。


谢谢。

解决方案

Re: 最后一行?
$


你好再次,

以下代码返回里面里面的第一个空白行已过滤的范围。

如果过滤的范围包含所有行中的数据,则它会立即返回
过滤范围内的行。

'---

Sub WhereAreYou()

Dim nextRow As Long

Dim R As Long



使用ActiveSheet.AutoFilter.Range

 对于R = .Rows.Count To 1 Step -1

    如果Application.WorksheetFunction.CountA(.Rows(R))> 0然后

      如果R> nextRow然后nextRow = R

      退出为
    结束如果

 下一个'R

  nextRow = nextRow + .Row

  MsgBox"自动过滤范围是:" &安培; 。地址& "  " &安培; vbCr& _

         "行" &安培; nextRow& "是空白。",","发生了什么事?"                   

Jim Cone

美国俄勒冈州波特兰市

https://goo.gl/IUQUN2
 (Dropbox)


(免费和商业excel加载项和工作簿)





Hi,

I have a dump of data that spans 20 columns, auto filters have been applied, the last row in the data range is blank in 17 of the columns and 3 of the columns have formulas in them.  The idea is that an end user completes a form which send the form data to the 17 columns of the last row in the data range, my macro drags those formulas down to the next row.

The issue I have is that I'm trying to determine the last row in the data range using the code below but if an auto filter is being applied it doesn't return the last row in the data range but returns the last filtered row + 1. How can I return the last row in the data return without deactivating the autofilters?

nextRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1

Help would be greatly appreciated.

Thanks.

解决方案

Re:  last row ?

Hello Again,
The following code returns the first blank row below all data inside the filtered range.
If the filtered range has data in all rows then it returns the row immediately below the filtered range.
'---
Sub WhereAreYou()
Dim nextRow As Long
Dim R As Long

With ActiveSheet.AutoFilter.Range
  For R = .Rows.Count To 1 Step -1
     If Application.WorksheetFunction.CountA(.Rows(R)) > 0 Then
       If R > nextRow Then nextRow = R
       Exit For
     End If
  Next 'R
  nextRow = nextRow + .Row
  MsgBox "Auto filter range is: " & .Address & "  " & vbCr & _
         "Row " & nextRow & " is blank.", , "what's going on ?"
End With
End Sub

'---
Jim Cone
Portland, Oregon USA
https://goo.gl/IUQUN2
 (Dropbox)

(free & commercial excel add-ins & workbooks)



这篇关于即使启用了“自动筛选”,也会在电子表格中获取最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆