Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving Right One Cell

I'm trying to move one cell to the right in a macro.

Range("C5").Select  <-- a formula that needs to be copied
Selection.Copy
Range("B5").Select
Selection.End(xlDown).Select
SendKeys ("{TAB}")
Range(Selection, Selection.End(xlUp)).Select
Selection.Paste

SendKeys does not appear to be the answer to this issue as it puts a TAB or RIGHT arrow directly into the next line of macro code, emulating keyboard strokes only. Is there another way to move my cell selection to the right from the end of Bn to Cn, where n is unknown?

like image 681
Mark Spain Avatar asked Oct 12 '25 00:10

Mark Spain


2 Answers

To reference one cell to the right of the active cell:

ActiveCell.Offset(0, 1)

To return the address of the cell one to the right:

MsgBox ActiveCell.Offset(0, 1).Address

To move the selection once cell to the right:

ActiveCell.Offset(0, 1).Select

Code from your answer but tidied up:

Range("C5").Copy
Range("B5").End(xlDown).Offset(columnoffset:=1).Activate
Range(Selection, Selection.End(xlUp)).Select

It doesn't really do anything. It copies but doesn't paste.

like image 101
ashleedawg Avatar answered Oct 14 '25 12:10

ashleedawg


your code can boil down to:

range("C5").Copy range("B5").End(xlDown).Offset(columnoffset:=1)

or, if you only need to paste values:

range("B5").End(xlDown).Offset(columnoffset:=1).value = range("C5").value
like image 28
DisplayName Avatar answered Oct 14 '25 12:10

DisplayName



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!