Board logo

標題: [發問] 輸入順序? [打印本頁]

作者: s7659109    時間: 2018-9-12 15:20     標題: 輸入順序?

本帖最後由 s7659109 於 2018-9-12 15:21 編輯

問題:key完b欄,A欄自動帶系統日期
需求:以第3列為例,當key 完1-4的順序後(限制輸入範圍),自動跳到下一列b欄,以此循環
作者: 准提部林    時間: 2018-9-13 10:09

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
     If .Count > 1 Or .Row = 1 Then Exit Sub
     If .Column = 2 Then
        If .Value = "" Then .Cells(1, 0).Resize(1, 6).ClearContents: Exit Sub
        .Cells(1, 0) = Format(Date, "emmdd")
     ElseIf .Column = 6 Then
        If .Value <> "" Then Range("B" & .Row + 1).Select
     End If
End With
End Sub
作者: s7659109    時間: 2018-9-13 10:50

本帖最後由 s7659109 於 2018-9-13 10:52 編輯

准大:可能沒說清楚,需求是

每輸入完一個儲存格,操作者,會按enter鍵
輸入順序
以第4列為例:b4 key完enter,a4帶入系統日期靠右,緊接著跳到c4,c4key完enter,跳到e4,key完enter跳到f4,key完跳下一列b5位置,以此循環
作者: 准提部林    時間: 2018-9-13 11:56

回復 3# s7659109


Private Sub Worksheet_Change(ByVal Target As Range)
With Target
     If .Count > 1 Or .Row = 1 Then Exit Sub
     If .Column = 2 Then
        If .Value = "" Then .Cells(1, 0).Resize(1, 6).ClearContents: Exit Sub
        .Cells(1, 0) = Format(Date, "emmdd")
     ElseIf .Column = 3 Then
        If .Value <> "" Then .Cells(1, 3).Select
     ElseIf .Column = 6 Then
        If .Value <> "" Then Range("B" & .Row + 1).Select
     End If
End With
End Sub
作者: s7659109    時間: 2018-9-13 12:29

准大:
b與e欄key完 enter後,會跳到下一列,不是原需求
作者: s7659109    時間: 2018-9-13 14:25

這樣改,可以用了,謝謝准大。
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
     If .Count > 1 Or .Row = 1 Then Exit Sub
     If .Column = 2 Then
        If .Value = "" Then .Cells(1, 0).Resize(1, 6).ClearContents: Exit Sub
        .Cells(1, 0) = Format(Date, "emmdd")
        .Cells(1, 2).Select
     ElseIf .Column = 3 Then
        If .Value <> "" Then .Cells(1, 3).Select
     ElseIf .Column = 5 Then
        If .Value <> "" Then .Cells(1, 2).Select
     ElseIf .Column = 6 Then
        If .Value <> "" Then Range("B" & .Row + 1).Select
     End If
End With
End Sub
作者: 准提部林    時間: 2018-9-13 15:28

一般輸入資料是由左而右, 按ENTER後, 是往右跳的, 在功能表設定即可
作者: s7659109    時間: 2018-9-14 09:00

准大還有另問題請教:
以第4列為例:b欄與c欄固定載入123 345,所以輸入欄位只有e欄與f欄,當e欄key完,自動帶出a b c欄,跳到f欄,當f欄key完,跳到下一列e欄,以此循環
作者: Hsieh    時間: 2018-9-14 09:54

回復 8# s7659109
  1. Private Sub Worksheet_Change(ByVal Target As Range) '儲存格內容變動
  2. If Target.Address Like "$E$*" Then
  3. Application.MoveAfterReturnDirection = xlToRight '設定輸入方向向右
  4. With Me
  5. .Unprotect '取消保護工作表
  6. .Range("E:F").Locked = False '取消輸入範圍的鎖定
  7. .EnableSelection = xlUnlockedCells '設定保護狀態下不能選取鎖定儲存格
  8. .Cells(Target.Row, 1).Resize(, 3) = Array(Format(Date, "emmdd"), 123, 345) '輸入A:C欄位
  9. .Protect '保護工作表
  10. End With
  11. End If
  12. End Sub

  13. Private Sub Worksheet_Deactivate() '離開工作表
  14. Application.MoveAfterReturnDirection = xlDown '還原輸入方向向下
  15. End Sub
複製代碼

作者: s7659109    時間: 2018-9-14 11:40

謝謝Hsieh,但還有個問題請教,若限定輸入欄位b c e f ,d欄位跳過,a 欄位帶入系統日期,請問以下這段如何改?
If Target.Address Like "$E$*" Then
Application.MoveAfterReturnDirection = xlToRight '設定輸入方向向右
With Me
.Unprotect '取消保護工作表
.Range("E:F").Locked = False '取消輸入範圍的鎖定
.EnableSelection = xlUnlockedCells '設定保護狀態下不能選取鎖定儲存格
.Cells(Target.Row, 1).Resize(, 3) = Array(Format(Date, "emmdd"), 123, 345) '輸入A:C欄位
作者: 准提部林    時間: 2018-9-14 12:54

回復 8# s7659109


Private Sub Worksheet_Change(ByVal Target As Range)
With Target
     If .Count > 1 Or .Row = 1 Then Exit Sub
     If .Column = 5 Then
        If .Value = "" Then .Cells(1, -3).Resize(1, 6).ClearContents: Exit Sub
        .Cells(1, -3) = Format(Date, "emmdd")
        .Cells(1, -2) = 123
        .Cells(1, -1) = 345
        .Cells(1, 2).Select
     ElseIf .Column = 6 Then
        If .Value <> "" Then .Cells(2, 0).Select
     End If
End With
End Sub
作者: s7659109    時間: 2018-9-14 14:35

謝謝准大,提供另一個思路!




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)