Copy and paste code


Posted by Alex Shahidi on January 28, 2002 7:53 AM

I am trying to write a code that copies a cell and pastes it in a cell (without using if-then formulas on the sheet).

Ex:

A1 = Jan
A2 = Feb

I want to paste the following:

B1= Jan
B2 = Feb

B1-B2 cannot contain any formulas. Thanks.

Alex

Posted by Keiser on January 28, 2002 8:05 AM

How about this

Range("A1:A2").Select
Selection.Copy
Range("B1").Select
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False

Hope it helps

Posted by Alex Shahidi on January 28, 2002 8:18 AM

Looks great, except that I have the following code that does not allow for that type of copying and pasting:

Private Sub worksheet_selectionchange(ByVal target As Range)
Application.CutCopyMode = False
Application.CellDragAndDrop = False
End Sub

Any other ideas? Thanks.

Alex

Posted by Keiser on January 28, 2002 8:35 AM

What about this, or is this out of the question too? (please work)

Dim nr1, nr2 As String

nr1 = Range("a1").Value
nr2 = Range("a2").Value

Range("b1").Value = nr1
Range("b2").Value = nr2

Hope it helps

Posted by Alex Shahidi on January 28, 2002 8:42 AM

This is great. Thank you so much! The only problem is that it is not just A1 and A2. Rather it is an array of A1:A500. I assume that this still works except that I need a shortcut code so that I won't have 500 lines of code. Thanks again.



Posted by Ivan F Moala on January 28, 2002 11:31 AM

Just use;
Range("B1:B500").Value = Range("A1:A500").Value


Ivan