Excel VBA - Drag and Drop Columns

I would like to enable a user to re-order columns.  When the user clicks down on the column header and hold the mouse down, I would like the column or some shape to become movable with the mouse.  When they let go of the mouse, I would then move the column to where they let go.

Does someone have some code that does most of this that I can cannibalize.
Who is Participating?
jnash67Connect With a Mentor Author Commented:
I ended up combining the code from the link listed above with code from here http://www.dailydoseofexcel.com/archives/2004/06/14/move-upmove-down-in-a-listbox/ to implement the solution.
Rory ArchibaldCommented:
Begs the question - why can't they just drag and drop anyway?
jnash67Author Commented:
It's in the context of a VBA dictator application where Excel is heavily modified.

There's a lot more details about the whys at http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_25008923.html
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

patrickabConnect With a Mentor Commented:

I know I said I would not respond in this question but I missed one crucial comment you made. Thus please see your old question for a solution - as well as here. The solution is in the attached file - code below.

Sub setup_column_select()
Application.OnKey "^{z}", "fred"
End Sub

Sub fred()
End Sub

Sub cancel_column_select()
Application.OnKey "^{z}"
End Sub

Open in new window

Rory ArchibaldConnect With a Mentor Commented:
Dictator apps should be overthrown, but that's another issue...

Why not use a userform with a listbox to allow them to reorder the columns as they see fit?
jnash67Author Commented:
I'm going with Rory's approach.  The problem with Patrick's approach was that the user still had to position cursor at the very edge and the program had no notification when the drag and drop was completed or where the column had been moved to.

I've started off with the code from: http://www.dailydoseofexcel.com/archives/2007/01/11/listbox-drag-and-drop/

Any ideas of how to highlight where an item is going to be dragged and dropped?  If not, any sample code for a listbox approach with an up and down button implemented?
jnash67 - Thanks for the points - Patrick
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.