看起來很容易的第一個空行,但我仍然無法弄清楚,爲什麼everyting被添加到A列,爲什麼不列「AN」我定義iRowB如何從用戶窗體中添加信息到2列,尋找每個
非常感謝您的幫助
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
爲什麼不直接創建兩個獨立的'iRow'值? 'iRowA'和'iRowB'。你已經有了'iRowA'這個代碼:'iRow = ws.Range(「A:A」)。Find(What:=「*」,SearchOrder:= xlRows,SearchDirection:= xlPrevious,LookIn:= xlValues).Row + 1',只需將'A:A'更改爲'iRowB'的'B:B'?如果這不是你想要做的,你可以更好地解釋你所要做的。 – jmac
它以某種方式不工作,如果我這樣做,如上所述。任何想法有什麼不對? – Adam
好,知道了,.Cells(iRowB,1)。價值= Me.Goal1.Value - 1進行修改,以 「AN」 – Adam