VBA - cut and paste selecton right

Tangled1

New Member
Joined
Dec 10, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi, I am trying to add a code to my document that after selecting a range with my mouse will move/cut the selection and move it to the next column to the right by an increment of 1.

The selection I have is I.e. C8:C11 which is coloured Red. After clicking a button I want the selection to move right each time, so i.e. D8:D11. Ideally I want the previous cells to remain the background colour (green) after cutting its cells.

Code I have right now, which doesn't work is:
VBA Code:
private sub commandbutton1_commandbutton1_click()
Dim myRange as Range
set myRange = selection
Selection.copy myRange.Offset(0,1).select
End sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Ok so I figured out how to move the selection forward. Just unable to keep colour format of the precious cells I'm cutting and move right.

Working code to move forward is:

VBA Code:
private sub commandbutton1_commandbutton1_click() 
Dim myRange as Range 
set myRange = selection 
Selection.cut 
myRange.Offset(0,1).select
Activesheet.paste
End sub
 
Upvote 0
How about
VBA Code:
Private Sub commandbutton1_commandbutton1_click()
   With Selection
      .Copy .Offset(, 1)
      .ClearContents
   End With
End Sub
 
Upvote 0
Solution
Thanks but this it is only coping the selection and leaving behind a trail of red cells. I have 2 background colours. Further back is green, background on top of that (to resemble a road) is grey. Using my code it cuts the red selection (c8:c11) to the next column and exposing the green background. I want to keep the previous selection grey. Will this too much hassle to worry about for me?
 
Upvote 0
How do you get two background colours on a cell?
 
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

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