Return to Previous Value When Using Combo Box in Excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • philqw78
    New Member
    • Jun 2010
    • 31

    #1

    Return to Previous Value When Using Combo Box in Excel

    I have a combo box with a pick list in excel.
    The combo box fires on double click of a cell with validation
    If the user then presses the escape key I wnat the linked cell to return to the previous value.

    So far I have got the double click to copy the original value into cell "A1"

    Then I have the following code on keystroke for the combo
    Code:
    Private Sub PickCombo_KeyDown(ByVal _
            KeyCode As MSForms.ReturnInteger, _
            ByVal Shift As Integer)
                 
        Application.ScreenUpdating = False
                   
        Select Case KeyCode
        
        Case 27 'escape
                
                Range("A1").Copy
                ActiveCell.Offset(0, 1).Select
                Application.ScreenUpdating = False
                Selection.Offset(0, -1).Select
                Application.ScreenUpdating = False
                Selection.PasteSpecial Paste:=xlPasteValues
                Application.CutCopyMode = False
                
            Case 9 'Tab
            Application.ScreenUpdating = False
                ActiveCell.Offset(0, 1).Select
                Application.ScreenUpdating = False
                Selection.Offset(0, -1).Select
                Application.ScreenUpdating = False
                Selection.Copy
                Selection.PasteSpecial Paste:=xlPasteValues
                Application.CutCopyMode = False
            Case 13 'Enter
                ActiveCell.Offset(0, 1).Select
                Application.ScreenUpdating = False
                Selection.Offset(0, -1).Select
                Application.ScreenUpdating = False
                Selection.Copy
                Selection.PasteSpecial Paste:=xlPasteValues
                Application.CutCopyMode = False
            
                
            Case Else
        End Select
        Application.ScreenUpdating = True
    End Sub
    This means if enter or tab are used the value is returned then copied and pasted over itself to fire an ON Change event.
    I can't get the original back in with escape though, trying to copy it back from A1.

    How do I get Excel to paste in the original target cell (the one that opened the combo), considering that cell could be anywhere in the worksheet because the combo box will fire on any cell with validation = 3.

    The active cell changes to A1. This is why it won't paste in the correct place. How do I get it back to the original cell that called the combo from A1 after copying it?
    Last edited by NeoPa; Apr 4 '12, 01:03 PM. Reason: Merged posts.
  • philqw78
    New Member
    • Jun 2010
    • 31

    #2
    Please don't answer this thread

    Sorry guys, I worked this out. Posted to soon due to frustration.

    I needed to monitor the target cell on the double click before this and use the monitored cell to get back in the Keydown.

    Code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    monitored2 = ActiveCell.Address
    ..... 'rest of code to call combo
    then
    Code:
    Private Sub PickCombo_KeyDown(ByVal _
            KeyCode As MSForms.ReturnInteger, _
            ByVal Shift As Integer)
        Select Case KeyCode
            Case 9 'Tab
                Range("A1").Copy
                Range(monitored2).Select
                Selection.PasteSpecial Paste:=xlPasteValues
                Application.CutCopyMode = False
    .... code for tab and enter

    Comment

    Working...