Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying a row in Excel to another sheet

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
623
GB
I would like to copy a row from one sheet to another in the same workbook.

By recording a macro in XL, I can see :
Range("B8:D8").Select
Selection.Copy
Sheets("Sheet2").Select
Range("B12").Select
ActiveSheet.Paste

I try to run this in VFP, with an object .zSheet1 representing the first sheet
.zSheet1.Range("B8:D8").Select
Selection.Copy

But I am failing on this second line because “Object ‘Selection’ does not exist”

Is “Selection” an object which only exists within Excel? What is the easiest way to copy this row.

Thanks. Andrew


 
Hello Andrew,

I haven't tested this, but I would guess that instead of this:

Code:
Range("B8:D8").Select
Selection.Copy

you do this:

Code:
Range("B8:D8").Copy

Selection does exist as an object outside of Excel, but in general it is easier to use the Range object directly (at least, that's my experience).

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Yes thanks Mike. That works. I am now failing on the "Paste" command. Excel has "Activesheet.paste" but I do not have activesheet.

I try .zSheet1.paste, but get "Unable to get the paste property of the worksheet class".

Have tried .zSheet1.range("C14").paste, but that gets "Unknown name".

----------------------

On a related issue, I would rather like to copy all of the properties of a cell (font &c) not just its value. But it seems that I have to copy each lowest level attribute individually. That is to say :

orange1.font = orange2.font - fails
orange1.font.name = orange2.font.name - succeeds
 
Andrew,

Have you tried:

Code:
oXL.ActiveWorkbook.ActiveSheet.Range("C14").Paste

Again, I'm not sure if it will work, but give it a try.

On your other question, I am slightly surprised that copying the entire object fails, but I can't recall every trying to do that. Sorry I have no suggestions.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top