Semi-Automatic Cut-Paste worksheet cells

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
I frequently need to move the contents of cells to blank cells. It becomes tedious to rightclick/cut, select new cell, rightclick/paste.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
I’d like to automate this task somehow and I’ve got half of a solution that works…<o:p></o:p>
<o:p> </o:p>
Select cell that I want to cut,<o:p></o:p>
Then, click CommandButton1 cuts the selected cell.<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Now I’m stuck…how to Doubleclick on the destination cell to paste.<o:p></o:p>
<o:p> </o:p>
Help with this or suggestions for a better method are appreciated.<o:p></o:p>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi there try the code below

Code:
Sub cutpaste()
Dim msg As String
Dim toRange As String
msg = InputBox("Select the cell to cut", "Cut - Paste")
toRange = InputBox("Select the cell to paste", "Cut - Paste")
Range(msg).Cut destination:=Range(toRange)
End Sub

Hope it helps

George


I frequently need to move the contents of cells to blank cells. It becomes tedious to rightclick/cut, select new cell, rightclick/paste.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I’d like to automate this task somehow and I’ve got half of a solution that works…<o:p></o:p>
<o:p></o:p>
Select cell that I want to cut,<o:p></o:p>
Then, click CommandButton1 cuts the selected cell.<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Now I’m stuck…how to Doubleclick on the destination cell to paste.<o:p></o:p>
<o:p></o:p>
Help with this or suggestions for a better method are appreciated.<o:p></o:p>
 
Upvote 0
How about posting the code you've got so far?

Here's the half that works...
Select cell/click CommandButton/select destination cell.

Code:
Private Sub CommandButton1_Click()
 
    ActiveCell.Select
    Selection.Cut
 
End Sub
 
Upvote 0
Hi there try the code below

Code:
Sub cutpaste()
Dim msg As String
Dim toRange As String
msg = InputBox("Select the cell to cut", "Cut - Paste")
toRange = InputBox("Select the cell to paste", "Cut - Paste")
Range(msg).Cut destination:=Range(toRange)
End Sub

Hope it helps

George

George, that works nice but it takes longer than the old cut/paste method. And with my keyboard skills it'll take me forever to input the cut and paste ranges. :)
 
Upvote 0
From your half-working code it appears that you would always be dealing with single cells. See if this is any use. It assumes that you would always be copying a cell containing data to a blank cell as that seems to be what you were describing in the first post.

Select both your Source and Target cells (use Ctrl + Click if they are not adjacent). It doesn't matter which order you select them so long as one is blank and the other is not. Then run the code (could be by clicking a button).

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Copy_Cell()<br>    <SPAN style="color:#00007F">Dim</SPAN> s <SPAN style="color:#00007F">As</SPAN> Range, t <SPAN style="color:#00007F">As</SPAN> Range, c <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> bDisplayMessage <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN><br>    <br>    <SPAN style="color:#00007F">If</SPAN> Selection.Cells.Count = 2 <SPAN style="color:#00007F">Then</SPAN><br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Selection.Cells<br>            <SPAN style="color:#00007F">If</SPAN> IsEmpty(c) <SPAN style="color:#00007F">Then</SPAN><br>                <SPAN style="color:#00007F">Set</SPAN> t = c<br>            <SPAN style="color:#00007F">Else</SPAN><br>                <SPAN style="color:#00007F">Set</SPAN> s = c<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> c<br>        <SPAN style="color:#00007F">If</SPAN> s <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Or</SPAN> t <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>            bDisplayMessage = <SPAN style="color:#00007F">True</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Else</SPAN><br>        bDisplayMessage = <SPAN style="color:#00007F">True</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    <SPAN style="color:#00007F">If</SPAN> bDisplayMessage <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "You need to select a single (occupied) Source cell" _<br>            & vbLf & "and a single (empty) Target cell"<br>    <SPAN style="color:#00007F">Else</SPAN><br>        s.Cut Destination:=t<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top