gpt4 book ai didi

vba - 在 Excel 中查找第一个空行并选择

转载 作者:行者123 更新时间:2023-12-04 22:03:02 35 4
gpt4 key购买 nike

我尝试改编这篇文章:Error in finding last used cell in VBA满足我的需要,但无法让它发挥作用。

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

'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

关于vba - 在 Excel 中查找第一个空行并选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31126531/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com