How to select the range for pasting using vba
Posted
by
user1616384
on Stack Overflow
See other posts from Stack Overflow
or by user1616384
Published on 2012-09-27T08:30:56Z
Indexed on
2012/09/27
9:37 UTC
Read the original article
Hit count: 193
I wrote some code for selecting the particular row and pasting it in column wise using paste-special property. It is working correctly my code is :
lngRow = Me.TextBox4.Value
strCol = Me.TextBox5.Value
Set rng = Range("A:A").Find(What:=lngRow, LookIn:=xlValues, LookAt:=xlWhole)
If rng Is Nothing Then
MsgBox "Value not found in row 1", vbExclamation
Else
Range(rng, rng.End(xlToRight)).Copy
Range("A1:E3").Columns(strCol).Offset(, 1).PasteSpecial Transpose:=True
Range("A1:E3").Rows(1).Copy
Range("A1:E3").Columns(strCol).PasteSpecial Transpose:=True
endif
the problem here is I am using Range(rng, rng.End(xlToRight)).Copy to copy the values and for pasting I am using Range("A1:E3").Columns(strCol).Offset(, 1).PasteSpecial Transpose:=True.
How can I paste all the values which are copied? Because if the values are in column F then this macro will not paste those values.
© Stack Overflow or respective owner