Consulting

Results 1 to 3 of 3

Thread: Solved: Copy Some cells from row 10 depending on which cells are selected in the active row.

  1. #1
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location

    Solved: Copy Some cells from row 10 depending on which cells are selected in the active row.

    Hi,

    When I select one or more cells in a single row,
    I want to be able to click a button to copy the values from the same columns in Row 10 to the selection.

    Edit: For clarification the selection will contain only adjacent cells.

    Thanks

  2. #2
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    I tinkered with it until I got it figured

    [vba]
    Option Explicit

    Private Sub CommandButton2_Click()

    Dim rng As range

    Set rng = Cells(10, Selection.Column).Resize(, Selection.Columns.Count)

    rng.Copy Cells(Selection.Row, Selection.Column)

    End Sub
    [/vba]

  3. #3
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    It eventually dawned on me that I only need one line,
    plus I figured I'd share how I'm doing the opposite.
    [vba]
    Private Sub CommandButton1_Click()
    '( Copy Row 10 corresponding cells to a single row range selected )
    Cells(10, Selection.Column).Resize(, Selection.Columns.Count).Copy Selection
    End Sub
    [/vba]
    opposite
    [vba]
    Private Sub CommandButton2_Click()
    '( Copying Selection in single row to row 10 )
    Selection.Copy Cells(10, Selection.Column)
    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
  •