返回列表 上一主題 發帖

一個表單請求協助

  1. Private Sub Label1_Click()
  2. Set a = Columns("A:A").Find(TextBox1.Text, lookat:=xlWhole)
  3. If a Is Nothing Then r = [A65536].End(xlUp).Row + 1 Else r = a.Row
  4. For i = 1 To 9
  5.    Cells(r, i) = Controls("TextBox" & i).Text
  6. Next
  7. End Sub

  8. Private Sub Label2_Click()
  9. Set a = Columns("A:A").Find(TextBox1.Text, lookat:=xlWhole)
  10. If a Is Nothing Then r = [A65536].End(xlUp).Row + 1 Else r = a.Row
  11. For i = 1 To 9
  12.    Cells(r, i) = Controls("TextBox" & i).Text
  13. Next

  14. End Sub

  15. Private Sub Label3_Click()
  16. ThisWorkbook.Save
  17. End Sub

  18. Private Sub Label4_Click()
  19. ScrollBar1.Value = Application.Max(ScrollBar1.Value - 1, ScrollBar1.Min)
  20. End Sub

  21. Private Sub Label5_Click()
  22. ScrollBar1.Value = Application.Min(ScrollBar1.Value + 1, ScrollBar1.Max)
  23. If ScrollBar1.Value = ScrollBar1.Max Then ScrollBar1.Max = ScrollBar1.Max + 1
  24. End Sub

  25. Private Sub ScrollBar1_Change()
  26. r = ScrollBar1.Value
  27. For i = 1 To 9
  28. Controls("TextBox" & i) = Cells(r, i).Value
  29. Next
  30. End Sub

  31. Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  32. Set a = Columns("A:A").Find(TextBox1.Text, lookat:=xlWhole)
  33. If Not a Is Nothing Then
  34. MsgBox "學號重複"
  35. With TextBox1
  36. Cancel = True
  37. End With
  38. End If
  39. End Sub

  40. Private Sub UserForm_Initialize()
  41. r = [A65536].End(xlUp).Row
  42. With ScrollBar1
  43. .Min = 3
  44. .Max = r + 1
  45. End With
  46. End Sub
複製代碼
回復 1# 周大偉
學海無涯_不恥下問

TOP

回復 3# 周大偉
增加一個刪除程序
  1. Private Sub Label15_Click()
  2. Set a = Columns("A:A").Find(TextBox1.Text, lookat:=xlWhole)
  3. If Not a Is Nothing Then a.Resize(, 9).Delete xlShiftUp
  4. End Sub
複製代碼
要刪除或修改都請使用上一筆、下一筆或捲軸讓學號為空白後再輸入
學海無涯_不恥下問

TOP

        靜思自在 : 人要知福、惜福、再造福。
返回列表 上一主題