[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 693
  • Last Modified:

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.
0
jnash67
Asked:
jnash67
  • 3
  • 2
  • 2
3 Solutions
 
Rory ArchibaldCommented:
Begs the question - why can't they just drag and drop anyway?
0
 
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
0
 
patrickabCommented:
jnash67,

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.

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

Sub fred()
Columns(Selection.Column).EntireColumn.Select
End Sub

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

Open in new window

column-selector-01.xls
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Rory ArchibaldCommented:
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?
0
 
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?
0
 
jnash67Author 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.
0
 
patrickabCommented:
jnash67 - Thanks for the points - Patrick
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now