Assignmentgeek.com - makes your homework shine. # Copy by Double-Click Mouse in Cell

## How using Double-Clicking Mouse in the Cell to copy the Value or Text to another Worksheet in the New Row

The Internet is full of different VBA macros that execute copying values when we press the left mouse button double-click on the cell. In this tutorial I will show some code to automatically copy by using the double click of the mouse.

The first Excel Example is copying values certain cells using double-clicking on a cell in one of the columns. In the picture below you will see that we have data on Sheet1 that we want to copy by using the double-click of the mouse. After the Double-Click the mouse we want to automatically value of the cell is copied to Sheet2, in a certain rows and columns (framed part of the picture below). Each time you click the mouse double-click on the cell automatically copies the contents of the cell on Sheet2 in new row below (in the destination column). For the above shown situation and automatically copy specified by double clicking the mouse, use the following VBA macro. Copy this VBA code below, in the VBE of Excel on your computer (ALT+F11), in the Sheet Module and try it.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Copy by mouse double-clicking
''''''''''''Column B on Sheet1
Dim r As Long 'Set up variables

If Target.Column = 2 Then 'column B on the worksheet Sheet1 from which we copy
Cancel = True
With Sheets("Sheet2") 'destination worksheet on which we're copying
r = .Range("D" & Rows.Count).End(xlUp).Row + 1 'destination column in the which we copy, the first free row or cell
r = IIf(r < 5, 5, r) 'first row ie. cell in the which is copy the first data, in this case row is five
.Range("D" & r).Value = Target.Value 'destination column and row
End With
End If 'The end command of IF function
'''''''''''Column C on Sheet2
If Target.Column = 3 Then
Cancel = True
With Sheets("Sheet2")
r = .Range("E" & Rows.Count).End(xlUp).Row + 1
r = IIf(r < 5, 5, r)
.Range("E" & r).Value = Target.Value
End With
End If
''''''''''''Column D on Sheet2
If Target.Column = 4 Then
Cancel = True
With Sheets("Sheet2")
r = .Range("F" & Rows.Count).End(xlUp).Row + 1
r = IIf(r < 5, 5, r)
.Range("F" & r).Value = Target.Value
End With
End If
End Sub

If you have a situation when only one column in question then the VBA macro code to remove the remaining columns (If ... End If)

## How to use the double-click the mouse to copy the adjacent cell or range of cells and the same row

In this second Excel Example you see how to use the double-click your mouse you can copy multiple cells in the same row to another worksheet or so the last copied data is always in the first place of destination worksheet.

In the picture below you see a situation in which a Worksheet 'Sheet1' using the mouse double-click in the column 'A', automatically copy the adjacent cell or range of cells to another worksheet 'Sheet2' but so that each new copy automatically be placed in the first row of the range of backup data and the previously copied data to be automatically shifted one row down. Simply, we want the last copy is always at the top of in the first row of copied data on 'Sheet2'. In the picture below you see framed part of the image is the result of copying double-clicking. To successfully copy double-clicking in a situation like above using VBA macro below (copy this macro in the VBE Module Sheet1 where you use the mouse double-click to copy).

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'double-click in the column A copy adjacent cell to another sheet in the B5:D5
'each new copy goes to the first row and the existing data is moving one row below
Dim vA As Variant
If Not Intersect(Target, Columns("A")) Is Nothing Then 'source column to double-click
vA = Target.Offset(0, 1).Resize(1, 3).Value 'variable displacement
With Sheets("Sheet2").Cells(5, 1) 'destination worksheet Sheet2 Row 5 Col 1
.EntireRow.Insert 'insert a new row
.Offset(-1, 1).Resize(1, 3).Value = vA 'move existing data for one row below
End With
End If
End Sub

## Automatically copy entire rows of double-clicking on any cell

In this third Excel example we have a situation where we want to automatically copy the entire row to another worksheet after you click the mouse double-click on any of the cells in a given row of the source Worksheet. In the picture below you will see that by double clicking with the mouse on any cell in a particular row on 'Sheet1' automatically copy the entire row to another Worksheet 'Sheet2' starting copying data from column 'B' and onwards. VBA macro to automatically copy your order by double-clicking the next. This VBA macro to copy in the Module sheet, your Workbook.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'double-click the mouse on the row to Sheet1 copies the entire row to Sheet2
Range(Cells(Target.Row, 2), Cells(Target.Row, 5)).Copy Destination:=Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Cancel = True
End Sub

The idea and the source data for this tutorial: Internet Network