AndresHernando
asked on
Excel VBA - Copy / Paste without using "selection"
I want to copy values of one row onto another row without "selecting"
Here's my attempt:
Range(vSourceRow).Copy Destination:=Range("2:2"). PasteSpeci al (xlPasteValues)
Here's my attempt:
Range(vSourceRow).Copy Destination:=Range("2:2").
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried reading the question? He specifically said he wanted to copy/paste without selecting.
You could also simply assign the .Value property from one range to the other.
ASKER
rorya,
what's the script for your suggestion? What I wrote below doesn't work.
Range("SourceRow").Value = Range("DestinationRow").Va lue
Thanks, --Andres
what's the script for your suggestion? What I wrote below doesn't work.
Range("SourceRow").Value = Range("DestinationRow").Va
Thanks, --Andres
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If Source and Destination are variables, you need to:
Range(DestinationRow).Valu e = Range(SourceRow).Value
Range(DestinationRow).Valu
ASKER
Cluskitt:
I tried your suggestion (see below), but it bugs out. What am I doing wrong?
Sub CopyRows()
Dim vSourceRow As Range
Dim vRowNum As Long
vRowNum = 9
Set vSourceRow = Range(vRowNum & ":" & vRowNum)
Range(vSourceRow).Copy '......................... .......... .......... .Bugs out here
Range("2:2").PasteSpecial (xlPasteValues)
End Sub
Tnx, --Andres
I tried your suggestion (see below), but it bugs out. What am I doing wrong?
Sub CopyRows()
Dim vSourceRow As Range
Dim vRowNum As Long
vRowNum = 9
Set vSourceRow = Range(vRowNum & ":" & vRowNum)
Range(vSourceRow).Copy '.........................
Range("2:2").PasteSpecial (xlPasteValues)
End Sub
Tnx, --Andres
vSourceRow is a Range, not an address, so:
vSourceRow.Copy
Range("2:2").PasteSpecial xlPasteValues
Yes, it all depends on the the variables you declare. If you declare it as a range, you have to use it as a range. For example, if you declared vSourceRow as String, then assigned it to: "9:9", you could then use Range(vSourceRow). If it's a range, you have to use it as rorya said. If you use it as integer and assign it the value 9, you have to use: Range(vSourceRow & ":" & vSourceRow)
ASKER
Thanks for the info. Both worked.
To be fair, I split, giving the extra 5pts to Cluskitt for answering first.
I'm not sure if this is the correct protocol... I just recently started using this site.
Please tell me if I am in breach of proper etiquette by splitting pts like I did.
To be fair, I split, giving the extra 5pts to Cluskitt for answering first.
I'm not sure if this is the correct protocol... I just recently started using this site.
Please tell me if I am in breach of proper etiquette by splitting pts like I did.
To my mind, you closed this properly - thank you! :)
I agree. Both answered the question using different approaches. Not that points are that important, but it's only fair to split things :)
ASKER
Great. Thanks again guys. --Andres
It would give you something like this:
Range("A1:B2").Select
Selection.Copy
Range("A4").Select
ActiveSheet.Paste