inetquestion
Technical User
I have a spreadsheet as shown below. VBA code was inserted so the double clicking on the cells in Colomn A where the months are listed would take the values in ROW1 and copy them to the row you clicked on. What modifications should be made so that this copy/paste would only occur if the destination cells were empty. Giving the user the option to clear them with a dialog box, or telling which cells were not empty would be nice, but not necessary. The VBA code to perform the copy/paste follows:
TIA,
-Inet
0 | 100 250 500 300 4525
--------------------------------------------
Jan| 100 250 500 300 4525
FEB| 100 250 500 300 4525
MAR| 100 250 500 300 4525
APR| 100 250 500 300 4525
MAY| 100 250 500 300 4525
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
Dim C As Range
Set C = Intersect(Target.Cells(1, 1), Range("A2:A100"))
If Not C Is Nothing Then
Range("B1:Z1").Copy
C.Offset(0, 1).PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Range("AC1").Copy
C.Offset(0, 28).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End If
Cancel = True ' cancels default double-click behavior
End Sub
TIA,
-Inet
0 | 100 250 500 300 4525
--------------------------------------------
Jan| 100 250 500 300 4525
FEB| 100 250 500 300 4525
MAR| 100 250 500 300 4525
APR| 100 250 500 300 4525
MAY| 100 250 500 300 4525
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
Dim C As Range
Set C = Intersect(Target.Cells(1, 1), Range("A2:A100"))
If Not C Is Nothing Then
Range("B1:Z1").Copy
C.Offset(0, 1).PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Range("AC1").Copy
C.Offset(0, 28).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End If
Cancel = True ' cancels default double-click behavior
End Sub