宏教程,查找VBA中特定列(如A)的最后一个空行 [英] macro tutorials finding last empty row in vba for particular column like A

查看:544
本文介绍了宏教程,查找VBA中特定列(如A)的最后一个空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为一个特定的库仑(例如A库仑)找到最后一个空行.


i want to find the last empty row for a particular coulmn like A coulmn .


sub abc()
iRow = wkb1.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
End Sub 


因为这仅占用了第一个库伦并为我提供Irow = 2,但是第二个B库伦存在数据.


请帮忙...
谢谢
aksh619


as this is taking only first coulmn and providing me with Irow = 2 but there is data present on second B coulmn .


Please help ...
thanks
aksh619

推荐答案

一些建议的解决方案
Some suggested solutions here[^].


您可以使用函数,如下所示:
You can use function, like this:
Function FirstEmptyRow(wsh As Worksheet, Optional sColName As String = "A") As Long
    FirstEmptyRow = wsh.Range(sColName & wsh.Rows.Count).End(xlUp).Row + 1
End Sub



用法:



Usage:

Dim lFirstEmptyRow AS Long
'default column (A):
lFirstEmptyRow = FirstEmptyRow(ThisWorkbook.Worksheets("Sheet1"))
'or - custom column:
lFirstEmptyRow = FirstEmptyRow(ThisWorkbook.Worksheets(2), "B")
'or (using Activesheet object):
lFirstEmptyRow = FirstEmptyRow(Activesheet, "C")


这篇关于宏教程,查找VBA中特定列(如A)的最后一个空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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