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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

zacemmel

Well-known Member
Joined
Apr 29, 2002
Messages
636
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
 

rikrak

Active Member
Joined
Aug 21, 2002
Messages
255
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>
 

Forum statistics

Threads
1,144,328
Messages
5,723,730
Members
422,512
Latest member
MHau5

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
Top