Vba 在Excel中找到第一个空行并选择

Vba 在Excel中找到第一个空行并选择,vba,excel,Vba,Excel,我试着使这篇文章适应我的需要,但没能完全发挥作用 我正在将数据粘贴到新工作表中,然后希望选择数据后的第一个空行。当前正在发生的是粘贴数据,然后选择工作表中的第一行。请参阅下面的代码。有什么想法吗 'runs when user enters data If Target.Cells.Count = 1 And _ Not Application.Intersect(Target, [I3:I10000]) Is Nothing Then Application.EnableEve

我试着使这篇文章适应我的需要,但没能完全发挥作用

我正在将数据粘贴到新工作表中,然后希望选择数据后的第一个空行。当前正在发生的是粘贴数据,然后选择工作表中的第一行。请参阅下面的代码。有什么想法吗

'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
尝试替换此:

'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

只是为了补充现有的答案。通过使用类似以下结构,可以避免进行太多选择:

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

嗨,这看起来和我的计划不太相符。它保持我刚刚粘贴的数据处于选中状态,我希望它位于该行的正下方。我尝试更改偏移值,但没有成功。有什么建议吗?解决了-我没打对电话。谢谢你的帮助!我很高兴如果下面的行不读取
.Cells(lastRow+1,1).EntireRow.select,我想最好是修复您提供的代码,这样做会有所帮助?