我有一個用於員工數據錄入工作的excel表單。 Excel表格包含員工的詳細信息。 我希望表單可以通過上一個和下一個按鈕瀏覽每個記錄,並在表單中顯示內容。使用上一個和下一個按鈕的行導航excel表格vba
我已經爲此寫了代碼,但它不能正常工作。有時會在記錄的開始和結束時提供無效的記錄詳細信息。幫助我
Private Sub UserForm_Initialize()
frmEmpDetails.ComboGender.AddItem "Male", 0
frmEmpDetails.ComboGender.AddItem "Female", 1
counter = ActiveSheet.UsedRange.Rows.Count
temp_counter = counter
lblTmpCount.Caption = temp_counter
End Sub
Private Sub btnNext_Click()
status = 1
lblTmpCount.Caption = temp_counter
If (temp_counter >= counter) Then
MsgBox "Reached end"
Else
temp_counter = temp_counter + 1
txtID.Text = Cells(temp_counter, 1).Value
txtName.Text = Cells(temp_counter, 2).Value
txtDOB.Text = Cells(temp_counter, 3).Value
ComboGender.Value = Cells(temp_counter, 4).Value
txtAboutEmp.Text = Cells(temp_counter, 5).Value
lblTmpCount.Caption = temp_counter
End If
End Sub
Private Sub btnPrev_Click()
status = 1
lblTmpCount.Caption = temp_counter
If (temp_counter < 2) Then
MsgBox "Reached beginning"
Else
txtID.Text = Cells(temp_counter, 1).Value
txtName.Text = Cells(temp_counter, 2).Value
txtDOB.Text = Cells(temp_counter, 3).Value
ComboGender.Value = Cells(temp_counter, 4).Value
txtAboutEmp.Text = Cells(temp_counter, 5).Value
temp_counter = temp_counter - 1
End If
End Sub