Chào A(c)
Em bắt đầu học VBA, có đoạn code trong sách như dứoi đây.
Khi click nút OK, để ghi thông tin Tên và giới tính, nhờ anh chị giải thích hộ chỗ họ viết khai báo biến, ngoài ra khi ấn F5 hiện Form và nhập liệu thì báo lỗi 424, chỗ này lNextRow = wf.CountA(Sheet1.Range("A:A")) + 1
Vậy nhờ A(c) giải thích dùm e với.
Cảm ơn
Em bắt đầu học VBA, có đoạn code trong sách như dứoi đây.
Khi click nút OK, để ghi thông tin Tên và giới tính, nhờ anh chị giải thích hộ chỗ họ viết khai báo biến, ngoài ra khi ấn F5 hiện Form và nhập liệu thì báo lỗi 424, chỗ này lNextRow = wf.CountA(Sheet1.Range("A:A")) + 1
Vậy nhờ A(c) giải thích dùm e với.
Cảm ơn
Mã:
Private Sub cmdOK_Click()
Dim lNextRow As Long
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
' Make sure a name is entered
If Len(Me.tbxName.Text) = 0 Then
MsgBox "You must enter a name."
Me.tbxName.SetFocus
Else
' Determine the next empty row
lNextRow = wf.CountA(Sheet1.Range("A:A")) + 1
' Transfer the name
Sheet1.Cells(lNextRow, 1) = Me.tbxName.Text
' Transfer the sex
With Sheet1.Cells(lNextRow, 2)
If Me.optMale.Value Then .Value = "Male"
If Me.OptFemale.Value Then .Value = "Female"
If Me.optUnknown.Value Then .Value = "Unknown"
End With
' Clear the controls for the next entry
Me.tbxName.Text = vbNullString
Me.optUnknown.Value = True
Me.tbxName.SetFocus
End If
End Sub
Sửa lần cuối bởi điều hành viên: