Consulting

Results 1 to 5 of 5

Thread: Solved: Copy Selection Paste btw 2 sheets

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Solved: Copy Selection Paste btw 2 sheets

    I am trying to make the following happen.
    I have the user select a range then click a button.

    That copies the selection and pastes it in another workbook.

    What I need to do is then go back to where the user made the initial selection and to the left of the selection copy a cell value (all cells to the left of the selection should be same value) after copying that cell go back to 2nd workbook and paste in "F2".

    I tried using SendKeys {Left}, but it doesn't seem to work, it keeps copying initial top cell.

    Any Ideas?

  2. #2
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    I was also thinking like using Offset, but don't know how to use it for this instance.

    Here is my code
    [vba] Selection.Copy
    Windows("Serial Scan.xlsm").Activate
    Range("B2").Select

    ActiveSheet.Paste

    Windows("Log.xlsm").Activate

    SendKeys "{LEFT}"
    'SendKeys "^{v}"

    Application.Wait (Now() + TimeValue("00:00:01"))

    Activecell.Copy

    Windows("Serial Scan.xlsm").Activate
    Range("F2").Select

    ActiveSheet.Paste[/vba]

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    This will suffice:


    [vba]Sub M_snb()
    Selection.Copy Workbooks("Serial Scan.xlsm").sheets(1).Range("B2")
    Selection.offset(,-1).resize(1,1).copy Workbooks("Serial Scan.xlsm").sheets(1).Range("F2")
    End Sub[/vba]


    NB. You didn't specify the name of the sheet in workbook 'Serial scan'.

  4. #4
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Thanks SNB that worked.

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    some improvement:

    [VBA]
    Sub M_snb()
    Selection.Copy Workbooks("Serial Scan.xlsm").sheets(1).Range("B2")
    Workbooks("Serial Scan.xlsm").sheets(1).Range("F2")=Selection.offset(,-1).resize(1,1).Value
    End Sub
    [/VBA]

Posting Permissions

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