Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jun 2002
    Location
    Toronto, Ontario
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    VB Express 2008 - Excel Oddity (VBExpress 2008)

    I have a VB Express application that takes input from a form and then populates an Excel spreadsheet. I want to copy 2 cells to the next row.

    Here is a code snippet:
    myRange = Nothing
    myRange = oShtMI.Range("G" & iRowMI & ":H" & iRowMI)
    myRange.Select()
    With myRange
    .Copy()
    .Cells(iRowMI + 1, iColMI - 1).select()
    .PasteSpecial()
    objAppXL.CutCopyMode = CType(False, XlCutCopyMode)
    End With
    myRange = Nothing

    To start
    iRowMI = 61 and iColMI = 8 -->H61
    and I want to paste G61 and H61
    to
    G62:H62

    The sixth line takes me to Cell M122 I start out at cell H61, how and why the heck do I end up at M122?

    What have I done wrong?

    Any help really appreciated.

    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VB Express 2008 - Excel Oddity (VBExpress 2008)

    Since iRowMI = 61, myRange is G61:H61. The line

    .Cells(iRowMI + 1, iColMI - 1).select()

    refers to myRange, so you're end up 61 rows down and 8 columns to the right of G61:H61. You should use MyRange.Offset(1, 0)

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VB Express 2008 - Excel Oddity (VBExpress 2008)

    By the way, it isn't necessary to select cells in order to copy and paste. I think you can replace all your code with

    With oShtMI.Range("G" & iRowMI & ":H" & iRowMI)
    .Copy() .Offset(1, 0)
    End With

Posting Permissions

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