Consulting

Results 1 to 10 of 10

Thread: Compile error

  1. #1

    Compile error

    Hi,

    I'm still a newbie!

    Trying to copy a range of cells in a row (starting at 6 columns from the cursor thru to col. 11 - in same row) and pasting it in cell G45.

    I keep getting compile error...":" is highlighted. See code below :

    Range(ActiveCell.Offset(0,6):ActiveCell.Offset(0,11)).Copy Range("G45")

    What ami doing wrong ...and what if i need to PasteSpecial instead of regualar paste (in need to transpose).

  2. #2
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Try this:

    Range(Cells(ActiveCell.Row, 6), Cells(ActiveCell.Row, 11).Copy Range("G45")

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With ActiveCell

    Range(.Offset(0,6), .Offset(0,11)).Copy Range("G45")
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Guys,

    Just got back..
    This one gave compile error:

    Range(Cells(ActiveCell.Row, 6), Cells(ActiveCell.Row, 11).Copy Range("G45")



    But this one worked :

    With ActiveCell

    Range(.Offset(0, 6), .Offset(0, 11)).Copy Range("G45")
    End With


    Thanks a lot....Now how would i Do a PasteSpecial with transpose ?

  5. #5
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    [vba]With ActiveCell

    Range(.Offset(0, 6), .Offset(0, 11)).Copy

    Range("G45").PasteSpecial Transpose:=True
    End With
    [/vba]

  6. #6
    Wow !!

    It worked!

    Now i'll try what i really need to do...copy from my orders sheet and paste to my sheet where quotes are prepared ...

    Thanks again!

  7. #7
    Back again..

    I tried pasting info to a different file and got Runtime error 9...Subscript Out of Range. Here's the code:

    With ActiveCell
    Range(.Offset(0, 6), .Offset(0, 12)).Copy
    Workbooks("pnvtest.xls").Sheets("Details").Range("addressLine1").PasteSpeci al xlPasteFormulas, Transpose:=True

    End With

    Help!

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Worked fine in my test. Is that workbook open?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    XLD,

    It works when the workbook is open...it wasn't !

    I tried including the file path to see if it would work with the target file closed. See code :

    With ActiveCell
    Range(.Offset(0, 6), .Offset(0, 10)).Copy
    Workbooks("C:\New Drive C\Education\VBA\R & D\pnvtest.xls").Sheets("Details").Range("addressLine1").PasteSpecial xlPasteFormulas, Transpose:=True
    End With

    It came back with the same "Subscript out of range" error. Does that mean i'll have to include a FileOpen command and FileClose each time ??

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can't copy to a closed workbook, it has to be open. I would add a test to see if it were open, and open it if not.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •