Macro revision

Sub Switch()
I created a macro called Switch to switch two numbers located in adjoining cells (one above the other).  My problem is that I want the switch to occur based on whichever cell I have highlighted so that it switches the number in that cell with the number in the cell one row below it.  Instead the macro only switches whatever data is in the cells originally used when I created the macro.  

'
' Switch Macro
' Switches two prices
'
' Keyboard Shortcut: Ctrl+Shift+S
'
    Selection.Copy
    Range("D37").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("D36:D37").Select
    Selection.Copy
    Range("D35").Select
    ActiveSheet.Paste
    Range("D37").Select
    Selection.ClearContents
End Sub


Can someone please show me how to modify the macro so that it works based on the highlighted cell and not a fixed cell?  Thanks!
pwflexnerAsked:
Who is Participating?
 
nutschCommented:
Like this?

' Switch Macro
' Switches two prices
'
' Keyboard Shortcut: Ctrl+Shift+S
dim vValue as variant

vvalue=selection.value
selection.value=selection.offset(1)
selection.offset(1).value=vvalue
End Sub

Open in new window

0
 
pwflexnerAuthor Commented:
Perfect!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.