Range selection not working

G

Guest

hi
Iam using officeXP and the following VBA code is not working in EXCEL. I would greatly appreciate if somebod
can tell me the correct way to do this code. I get 'select method of range class failed" error message

' here is the cod
dim cvalue as intege
cvalue=
Worksheets("sheet2").Selec
Range(Cells(cvalue, 1), Cells(cvalue, 54)).Selec
Selection.Cop
Sheets("Sheet3").Selec
Rows("2:2").Selec
ActiveSheet.Past

' end of cod

thank
Kana
Any ideas?
 
B

Bob Phillips

Hi Kanan,

You are not mapping the source onto the same size target. The problem is in
the Rows("2:2")

So instead of

Rows("2:2").Select

you could use

Range("A2").Select

which will copy into A2 across

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

kanan said:
hi,
Iam using officeXP and the following VBA code is not working in EXCEL. I
would greatly appreciate if somebody
 
G

Guest

Thank You Bob. That worked great

But I am still not sure why Rows("2:2") is not the same as Range("A2").
I guess my understanding of the Rows is not correct. can you please explain
thank
Kanan
 
B

Bob Phillips

Hi Kanan,

Rows("2:2") refers to the whole row, al 256 cells. You are copying 54 cells,
and when you try to paste 54 onto 256, you get an error. But if you try and
paste 54 onto 1 (which Range("A2") is, it copies across or down the
requisite number of cells, as in the source.

The same happens in Excel,. Select A1:J1 and copy. Then select row 5 and try
and paste, you will get an error. Select A5 and paste, and you will see it
paste all the way across to J5.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top