Cutting and Pasting using a Command Button

thegreatcorn69

New Member
Joined
Aug 7, 2018
Messages
2
Hi There,

I have read a couple of forums on this but am still not getting it right. Lets say I have 2 worksheets. Sheet 1 and Sheet 2.

I would like to have my command button do the following:

1. Cut the selected cell from my existing worksheet (this I have achieved albeit through assistance and not sure if it is correct)
2. Select Sheet 2
3. Find the next available column in Sheet 2
4. Paste the cut field in the sheet
5. As an added bonus I would like to be able to copy the text in another field in Sheet 1 to another adjacent field in Sheet 2.

Here is the code I have so far :

Private Sub CommandButton1_Click()


Dim a As Worksheet
Dim b As Worksheet
Set a = Sheets("Main Pipeline")
Set b = Sheets("Past")
a.Select
Selection.Cut
b.Select

b.Range("A1").End(xlUp).Offset(1, 0).Value = a.Range("a1").Value
End Sub

This code cuts the field but then does not insert it automatically into the next available column in my second sheet. Also - this does obviously not address point 5

Can someone help?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
thegreatcorn69,

Welcome to the board.

The posted code doesn't quite match what you've stated in items 1 to 5, so the following is a guess at what you're trying to achieve...

Code:
Private Sub CommandButton1_Click()
Dim a As Worksheet, b As Worksheet
Dim rng As Range
Set a = Sheets("Main Pipeline")
Set b = Sheets("Past")

Set rng = Application.InputBox(prompt:="Please select a range.", Type:=8)
Application.ScreenUpdating = False
rng.Cut
b.Paste Destination:=b.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) 'Pastes into the next blank row of Column A
End Sub

Cheers,

tonyyy
 
Upvote 0
thegreatcorn69,

Welcome to the board.

The posted code doesn't quite match what you've stated in items 1 to 5, so the following is a guess at what you're trying to achieve...

Code:
Private Sub CommandButton1_Click()
Dim a As Worksheet, b As Worksheet
Dim rng As Range
Set a = Sheets("Main Pipeline")
Set b = Sheets("Past")

Set rng = Application.InputBox(prompt:="Please select a range.", Type:=8)
Application.ScreenUpdating = False
rng.Cut
b.Paste Destination:=b.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) 'Pastes into the next blank row of Column A
End Sub

Cheers,

tonyyy


Hi Tony,

Thanks for this. This is exactly what I needed!!
 
Upvote 0

Forum statistics

Threads
1,215,743
Messages
6,126,613
Members
449,322
Latest member
Ricardo Souza

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