Is it possible to move data from one cell to another by clicking once in a source cell then click once in another, target cell?

Looking at ways that I can simplify actions in an Excel sheet on a touch screen.

Is it possible to move data from one, source cell, to a target cell simply by clicking once on a single cell then click once on the target cell.
I would like to move data only, no formatting.

Thanks
spar-kleOperations DirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ fanpages ]IT Services ConsultantCommented:
Yes, that is possible.

How would you cancel a selection once a cell had been identified as being the source?

Clicking back on the same cell is probably possible, but a lot more work.

A "cancel" option by another means may be easier to implement.
spar-kleOperations DirectorAuthor Commented:
First touch could change a control cell or value of a variable...
[ fanpages ]IT Services ConsultantCommented:
Please go on, as I think you have either misunderstood my point about cancelling a selection, or I have not understood your requirements.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Without knowing the exact requirement, a workaround this based on your description is only possible if you know the range which you will need to copy.

Like if you know that you will always copy one of the cell in the range, say A2:A? where ? denotes the last row with data in col. A and paste the value of the selected cell to another cell you select next, you may use the Sheet Selection Change Event to achieve this...

Right click on the Sheet Tab --> View Code --> Paste the code given below into the opened code window --> Close VBA Editor --> Save your workbook as Macro-Enabled Workbook.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Dim lr As Long
Dim cell As Range
Dim val
lr = Cells(Rows.Count, "A").End(xlUp).Row       'Finds the last row with data in col. A
Application.EnableEvents = False
If Not Intersect(Target, Range("A2:A" & lr)) Is Nothing Then
    val = Selection.Value
    On Error Resume Next
    Set cell = Application.InputBox("Please select the destination cell.", Type:=8)       'Select the destination cell
    If Err = 0 Then
        cell.Value = val
    Else
        Application.EnableEvents = True
        Exit Sub
    End If
End If
Application.EnableEvents = True
End Sub

Open in new window

See if this is something you can work with.
spar-kleOperations DirectorAuthor Commented:
Thanks for your answers.
I'm really looking for code in the worksheet for a single click event that will trigger like a double click event.

I don't think there is a single click event, so I'm looking for a workaround that does the same thing.
I will have other code for double click events.

Objective:
First click cuts the contents of the selected cell.
Second click pastes data into the selected cell, without formatting.

Will figure out cancellation as next step.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Selecting a cell with mouse is equivalent to the single click. Isn't it?
Though the sheet selection change event will also be triggered when the selection is changed with other navigation methods instead of a mouse click.
spar-kleOperations DirectorAuthor Commented:
Yes
However as indicated this will be used on a touch screen.

Been thinking.
As an alternative could use a right click??
This may be better because I think on a touch screen in a Windows environment this is a long click.
Correct?
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
The same code can be modified to work for Before Right Click Event....

Apply the code to the sheet module as per the earlier instructions.
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Dim cell As Range
Dim val
Application.EnableEvents = False
    val = Selection.Value
    On Error Resume Next
    Set cell = Application.InputBox("Please select the destination cell.", Type:=8)       'Select the destination cell
    If Err = 0 Then
        cell.Value = val
        Cancel = True
    Else
        Application.EnableEvents = True
        Exit Sub
    End If
Application.EnableEvents = True
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
[ fanpages ]IT Services ConsultantCommented:
How about a selection change (a click on a touch-screen device) to indicate the source cell, followed by a further selection change (another click) to indicate destination cell, but the second cell selection has to be within a certain duration; for example, within two seconds?

This duration could be variable to suit your needs, of course, but it then means that a cancellation of the action would simply be the lack of near-immediate selection of the destination cell.

An issue I can see with this approach, however, is that if you miss the window of opportunity to indicate the destination cell after selecting the source cell, then you would have to click (selection change) elsewhere in order to then start the selection of the source cell again after the 'timeout' period has elapsed.

That is, select cell [C10], with the intention of moving the contents to cell [D12], but take longer than 2 seconds to locate cell [D12]; upon arrival at that cell, the move does not occur, so you then have to wait a further 2 seconds to be able to re-select cell [C10] again, & then choose [D12] thereafter within the next 2 second period.

You may find that if the "timeout" is not long enough to navigate to the destination cell, then you may be constantly selecting the source cell until you reach the destination within the designated period.  It would make an interesting game if you had the time to play though.

The best approach here is showing the current status of the move operation on the Application's StatusBar, so you know when the source cell ([C10]) is selected ready to be moved.  When the "timeout" period has been reached, the StatusBar is updated to reflect that the source cell is no longer selected for the move operation.


However, yes, a right (or "long") click does seem to be a better method... although, you would then lose the context-sensitive pop-up menu of options usually displayed on a right-click event.

How about holding down the [CTRL], [SHIFT], or [ALT] key (or a combination of two/three of these keys) whilst selecting the source cell?   Is that possible on a touch-screen device, or would an on-screen keyboard inhibit the view of the worksheet?
spar-kleOperations DirectorAuthor Commented:
Excellent, thanks sktneer
Works a treat
spar-kleOperations DirectorAuthor Commented:
If I would like to clear the original cell contents, where should i insert code please/
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Glad it worked for you.

Make the change here to clear the cell content.

Application.EnableEvents = False
    val = Selection.Value
    Selection.ClearContents

Open in new window

If you want to clear everything including formatting, use Clear instead of ClearContents.
[ fanpages ]IT Services ConsultantCommented:
Oh... solution accepted without discussing further.

OK :)

Another one for you sktneer... grrrr! ;)

Seriously, though, spar-kle, if you think there is some mileage in my proposal, please let me/us know.

Thanks.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
I think you should make the following changes to clear the cell content if you select the destination cell otherwise the cell content will not be cleared...
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Dim cell As Range
Dim val
Application.EnableEvents = False
    val = Selection.Value
    On Error Resume Next
    Set cell = Application.InputBox("Please select the destination cell.", Type:=8)       'Select the destination cell
    If Err = 0 Then
        Selection.ClearContents
        cell.Value = val
        Cancel = True
    Else
        Application.EnableEvents = True
        Exit Sub
    End If
Application.EnableEvents = True
End Sub

Open in new window

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Another one for you sktneer... grrrr! ;)
Cool. I think my approach is easier to follow. Isn't it?
[ fanpages ]IT Services ConsultantCommented:
:)

Keeping it simple is often a good approach, yes.

I like making solutions difficult because I can,... obviously! ;)

(I just really like giving somebody exactly what they have asked for, or offering a better proposal to their initial requirement, if I can).

No worries... I'll get you "next time"! :)
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
I like making solutions difficult because I can,... obviously! ;)
Isn't quite a good approach to prove yourself. Think about it. :)
spar-kleOperations DirectorAuthor Commented:
Thanks Guys.

Sorry fanpages.
Believe it or not I missed your really long comment because I quickly scrolled down to the bottom of the page!! ...really sorry...
I like sktneer's suggestion because of simplicity, but I will check it out fully for best operation on a touch screen.

Will post another question if other problems arise.

Thanks for the revised code sktneer!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome spar-kle!
[ fanpages ]IT Services ConsultantCommented:
No problem, spar-kle.

If I see you post again on the same subject, I will stop by to see if I can help (further).

Good luck with your project.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.