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

时间:2013-08-27 21:28:44

标签: excel userform

看起来非常简单,但我仍然无法弄清楚为什么所有内容都会添加到A列,为什么不能找到“AN”列,因为我已经定义了iRon 非常感谢您的帮助

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

1 个答案:

答案 0 :(得分:0)

在.Cells(iRow,1)中,iRow是行号,1是列号。 1是A列,2是B列,等等。所以如果你想让目标在B列......

.Cells(iRow, 2).Value = Me.Goal1.Value

或者,您可以输入列字母:

,而不是列号
.Cells(iRow, "B").Value = Me.Goal1.Value