+ Reply to Thread
Results 1 to 6 of 6

Drag and drop text in one click

Hybrid View

  1. #1
    Registered User
    Join Date
    04-08-2019
    Location
    london
    MS-Off Ver
    0365
    Posts
    3

    Drag and drop text in one click

    Hi All,

    I am struggling to find an elegant solution for drag and drop. My requirement is dragging some text from a 'menu' and dropping it in an excel cell in one click.
    My current solution is using the web browser vba control and using hyperlinks as the 'drag and drop object' but it requires end users to make changes in the registry editor which is a big no no.

    I am happy for the menu of text items to exist in a userform but the text must end up in the standard excel cells

    thank you





    drag and drop.png

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Drag and drop text in one click

    If the value is in the active cell ...
    Sub CopyAndDrop()
        ActiveCell.Copy Application.InputBox("Paste where?", , , , , , , 8)
    End Sub
    Sub CopyDropAndDeleteOriginal()
        Dim cel As Range: Set cel = ActiveCell
        cel.Copy Application.InputBox("Paste where?", , , , , , , 8)
        cel.ClearContents
    End Sub
    Attach a shortcut to whichever macro does what you need

    The input box allows the user to type in the destination cell address or to click on that cell
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    04-08-2019
    Location
    london
    MS-Off Ver
    0365
    Posts
    3

    Re: Drag and drop text in one click

    Is there a way to accomplish this with less clicks? At the very least, if I create a on selection change sub routine, this operation can be done with 2 clicks.
    Is it possible to do it with one click? By dragging and dropping?

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Drag and drop text in one click

    two options using event macros

    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
        If Not Intersect(Range("A2:A1000"), Target) Is Nothing Then
            Cancel = True
            Target.Copy Application.InputBox("Paste where?", , , , , , , 8)
        End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.CountLarge > 1 Then Exit Sub
        If Not Intersect(Range("A2:A1000"), Target) Is Nothing Then Target.Copy Application.InputBox("Paste where?", , , , , , , 8)
    End Sub

  5. #5
    Registered User
    Join Date
    04-08-2019
    Location
    london
    MS-Off Ver
    0365
    Posts
    3

    Re: Drag and drop text in one click

    Thank you Kev for your responses. However, both options still require the user to first click on the item they want to copy and then click on the destination, which is 2 clicks.
    What I am looking for is a drag and drop experience

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Drag and drop text in one click

    Another option
    - click in range A2 to A1000 and copy that value to any cell clicked (here in range J2 to J1000)

    'declare variables at TOP of sheet module above all procedures
    
    Private Cel As Range, Drag As Boolean
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.CountLarge > 1 Then Exit Sub
    'copy from here
        If Not Intersect(Range("A2:A1000"), Target) Is Nothing Then
            Set Cel = Target
            Drag = True
        End If
    'paste here
        If Not Intersect(Range("J2:J1000"), Target) Is Nothing Then
            If Drag = True And Not Cel Is Nothing Then
                Cel.Copy Target
                Set Cel = Nothing
                Drag = False
            End If
        End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 11-03-2018, 04:26 PM
  2. Click and drag VBA?
    By Hambone70 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-10-2016, 04:29 AM
  3. [SOLVED] Drag and Drop data using Treeview -Working great for the first drop, but locking on 2nd
    By graym463 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2016, 09:38 AM
  4. Replies: 2
    Last Post: 04-07-2015, 04:01 PM
  5. Drag & Drop text from listbox to cell
    By CuvelieY in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-15-2011, 09:48 AM
  6. Drag & Drop Only Values Via Left Click...?
    By gandolff in forum Excel General
    Replies: 1
    Last Post: 09-14-2009, 09:57 PM
  7. [SOLVED] how do I drag & drop cell text only
    By Kirstie in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-10-2006, 10:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1