VBA Question

johnhan

New Member
Joined
Oct 27, 2002
Messages
8
I have made the following routine to go to the right side of some rows and copy the right most cells and paste it to the right of the formerlly right most cells. I now want to add a routine that will take the selection back to the first cell that I have just added. Thanks!

Sub addmonth()

Range("t7").End(xlToRight).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial

Range("t8").End(xlToRight).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial

Range("t9").End(xlToRight).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial

Range("t11").End(xlToRight).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Range("t7").End(xlToRight).Select
Selection.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial

Just a suggestion, but you can make your code a lot more efficient by doing the following:

range("t7").copy
range("t7").offset(0,1).pastespecial



_________________
Questions?<a href=http://www.excelquestions.com>http://www.excelquestions.com</a>
This message was edited by zacemmel on 2002-10-28 15:32
 
Upvote 0
hi johnhan,

If you mean you want to activate the cell that was active before you copied some values, save the position, do the copy and activate the saved position:

<pre>
dim cl as Range
Set cl = ActiveCell 'save position
'.........
' do your stuff
'........
cl.Select ' select saved position
</pre>
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,249
Members
448,879
Latest member
oksanana

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