Excel 如何将userform中的信息添加到两列中,查找每列中的第一个空行

Excel 如何将userform中的信息添加到两列中,查找每列中的第一个空行,excel,userform,Excel,Userform,看起来很简单,但我仍然不明白为什么每次都要添加到A列,为什么不添加到我定义的iRowB列“AN”中 非常感谢你的帮助 Private Sub CommandButton1_Click() Dim iRowA As Long Dim iRowB As Long Dim ws As Worksheet Set ws = Worksheets("Results draft") 'find first empty row in database iRowA = ws.Range("A:A").Fi

看起来很简单,但我仍然不明白为什么每次都要添加到A列,为什么不添加到我定义的iRowB列“AN”中

非常感谢你的帮助

Private Sub CommandButton1_Click()

Dim iRowA As Long
Dim iRowB As Long
Dim ws As Worksheet
Set ws = Worksheets("Results draft")

'find first empty row in database

iRowA = ws.Range("A:A").Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

iRowB = ws.Range("AN:AN").Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1


If Trim(Me.HomeTeam.Value) = "" Then
Me.HomeTeam.SetFocus
MsgBox "Please insert the result"
Exit Sub
End If


With ws

.Cells(iRowA, 1).Value = Me.HomeTeam.Value


.Cells(iRowB, 1).Value = Me.Goal1.Value



End With
End Sub
在.Cells(iRow,1)中,iRow是行号,1是列号。1是A列,2是B列,等等。所以如果你希望目标在B列

.Cells(iRow, 2).Value = Me.Goal1.Value
或者,您可以将列字母替换为列号:

.Cells(iRow, "B").Value = Me.Goal1.Value

但是iRow被定义为=ws.Range(“A:A”).Find(What:=“*”,SearchOrder:=xlRows,SearchDirection:=xlPrevious,LookIn:=xlValues)。行+1是A列中的第一个空行。如果我说(iRow;B)这并不意味着BWY列中的第一个emty行为什么需要不同行上的相应数据?为什么不创建两个单独的
iRow
值<代码>iRowA和
iRowB
。您已经有了带有此代码的
iRowA
iRow=ws.Range(“A:A”).Find(What:=“*”,SearchOrder:=xlRows,SearchDirection:=xlPrevious,LookIn:=xlValues)。行+1
所以只需将
iRowB
A:A
更改为
B:B
?如果这不是你想做的,你可以更好地解释你在做什么。如果我像上面那样做,它不知怎么地不起作用。知道怎么回事吗?好的,知道了,.Cells(iRowB,1).Value=Me.Goal1.Value-1修改为“AN”