PDA

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



frank_m
04-07-2012, 06:35 PM
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

frank_m
04-07-2012, 09:19 PM
I tinkered with it until I got it figured :)


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

frank_m
04-09-2012, 02:02 AM
It eventually dawned on me that I only need one line,
plus I figured I'd share how I'm doing the opposite.

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

opposite

Private Sub CommandButton2_Click()
'( Copying Selection in single row to row 10 )
Selection.Copy Cells(10, Selection.Column)
End Sub