需要一个函数来返回工作表中填充了空闲单元格的第一个完全空的行(没有值,没有公式,没有空白)。不需要填写任何一列。
我试过了,但我甚至可以编译它:
Public Donations As Worksheet
Set Donations = Sheets("Sheet2")
Function getEmptyRow() As Long
Dim lastCol As Long, lastRow As Long, maxRow As Long
Dim col As Long
Dim r As Variant
lastCol = Donations.Cells(1, Columns.Count).End(xlToLeft).Column
For col = 1 To lastCol Step 1
lastRow = Donations.Cells(Rows.Count, col).End(xlUp).row
maxRow = Application.WorksheetFunction.max(maxRow, lastRow)
Next col
getEmptyRow = maxRow + 1
End Function发布于 2016-06-02 07:01:14
使用EntireRow (让我告诉您,这是非常有用的)并从A1开始逐行计数是一种非常基本的方法。
这将在“即时”窗口中告诉您:
Sub findemptyrow() '''Psuedo Code
Application.ScreenUpdating = False 'turns off annoying blinky
Range("a1").Activate 'start at beginning
While a <> 1 'keep going
If Application.CountA(ActiveCell.EntireRow) = 0 Then 'is it blank?
Debug.Print "Row " & (ActiveCell.Row) & " is blank." 'it is
a = 1 'stop going
End If
ActiveCell.Offset(1).Activate 'next cell
Wend 'do it all over again
Application.ScreenUpdating = True 'back to normal settings
End Sub将ScreenUpdating设为False会使速度更快,即使有10k行。
https://stackoverflow.com/questions/37580130
复制相似问题