0

看起来很简单,但我仍然无法弄清楚为什么每一个都被添加到 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
4

1 回答 1

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
于 2013-08-27T22:10:23.813 回答