在Excel中find第一个空行并select

我试图适应这个职位: 在VBA中find最后使用的单元格错误,以我的需要,但不能完全得到它的工作。

我正在将数据粘贴到新的工作表中,然后希望在数据之后select第一个空行。 目前发生的事情是数据被粘贴,然后select表格中的第一行。 看下面的代码。 有什么想法吗?

'runs when user enters data If Target.Cells.Count = 1 And _ Not Application.Intersect(Target, [I3:I10000]) Is Nothing Then Application.EnableEvents = False 'User inputs type of event Archive = InputBox("Was this event a Win, Loss, or Close? (Please input Win/Loss/Close)") With Target If Archive = "Win" Then 'all data to transfer is selected and cut .EntireRow.Select Selection.Cut 'the receiving sheet is selected and data is pasted to the selected cell Sheets("Win").Select ActiveSheet.Paste 'the selection on the sheet the data was cut from is deleted Sheets("Begin").Select Selection.Delete 'this is the issue I'm having - I want to select the row below the row I just copied into. Sheets("Win").Select lastRow = Range("C" & .Rows.Count).End(xlUp).Row ActiveSheet.Range("C" & lastRow & ":C" & lastRow).EntireRow.Select Sheets("Begin").Select 

尝试replace这个:

 'this is the issue I'm having - I want to select the row below the row I just copied into. Sheets("Win").Select lastRow = Range("C" & .Rows.Count).End(xlUp).Row ActiveSheet.Range("C" & lastRow & ":C" & lastRow).EntireRow.Select 

有了这个:

 With Sheets("Win") lastRow = .Range("C" & .Rows.Count).End(xlUp).Row .Cells(lastRow + 1, 1).EntireRow.Select End With 

只是添加到现有的答案。 你可以避免做这么多的select,通过使用更像这样的结构:

 On Error GoTo problem Dim Archive As String If (Target.Cells.Count = 1) And _ Not (Excel.Application.Intersect(Target, [I3:I10000]) Is Nothing) Then Excel.Application.EnableEvents = False 'User inputs type of event Archive = InputBox("Was this event a Win, Loss, or Close? (Please input Win/Loss/Close)") With Target '>>>> good idea to defend against users entering "win" instead of "Win" If (LCase(Archive) = "win") Then '>>>> find the last row in Win sheet at the beginning With Sheets("Win") lr = .Range("C" & .Rows.Count).End(Excel.xlUp).Row End With '>>>> as you are cutting there should be no need to do any subsequent deletion or clearcontents .EntireRow.Cut Sheets("Win").Rows(lr + 1) End If End With End If problem: Excel.Application.EnableEvents = True