返回列表 上一主題 發帖

[發問] 下拉式選單的更新

回復 3# bridetobe

不會有這樣情形才對,上傳檔案來看看
學海無涯_不恥下問

TOP

回復 5# bridetobe

會自動更新丫!你怎麼操作的?

    play.gif
學海無涯_不恥下問

TOP

回復 7# bridetobe
要更改已經輸入內容就必須重新寫入
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. Dim A As Range
  3. If Target.Column <> 2 Then Exit Sub
  4. With Sheet3
  5. ThisWorkbook.Names.Add "清單", "=OFFSET(" & .Name & "!$A$1,,,COUNTA(" & .Name & "!$A:$A),)"
  6. With Range("B:B").Validation
  7.    .Delete
  8.    .Add xlValidateList, , , "=清單"
  9. End With
  10. Select Case Target.Value
  11. Case "新增"
  12. newitem = InputBox("輸入新增項目")
  13. If Application.CountIf([清單], newitem) = 0 Then
  14.    Set A = .Columns("A:A").Find("新增", lookat:=xlWhole)
  15.    A.Insert xlShiftDown
  16.    A.Offset(-1) = newitem
  17.    Target = newitem
  18. Else
  19.    MsgBox "項目已存在清單內"
  20. End If
  21. Case "刪除"
  22. delitem = InputBox("輸入刪除項目")
  23. Set A = .Columns("A:A").Find(delitem, lookat:=xlWhole)
  24. If A Is Nothing Then
  25.    MsgBox delitem & "不存在清單內"
  26.    Else
  27.    A.Delete xlShiftUp
  28. End If
  29. Case "修改"
  30. chitem = InputBox("輸入修改項目")
  31. Set A = .Columns("A:A").Find(chitem, lookat:=xlWhole)
  32. If A Is Nothing Then
  33.    MsgBox chitem & "不存在清單內"
  34.    Else
  35.    A.Value = InputBox("輸入更正項目", , chitem)
  36.    Target = A
  37.    Range("B:B").Replace chitem, A  'B欄所有已經輸入的資料一起替換
  38. End If
  39. End Select
  40. End With
  41. With Range("B:B").Validation
  42.    .Modify xlValidateList, , , "=清單"
  43. End With
  44. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 太陽光大、父母恩大、君子量大,小人氣大。
返回列表 上一主題