Hi all my code is as follows
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim wks As Worksheet
Dim lastrow5 As Integer
Dim ecolumn As Long
Set wks = Worksheets("Form")
Application.ScreenUpdating = False
lastrow5 = Worksheets("Form2").Cells(Rows.count, 1).End(xlUp).Row
If Not Intersect(Target, Range("A1:R42")) Is Nothing Then Exit Sub
If Not Intersect(Target, Range("B43:B" & lastrow5)) Is Nothing Then Exit Sub
If Not Intersect(Target, Range("A43:A" & lastrow5)) Is Nothing Then
Worksheets("Form").Range("B16:C36").ClearContents
Worksheets("Form").Range("B16:C36").Cells.Validation.Delete
Worksheets("Form").Range("B16:B35").Interior.Color = RGB(255, 255, 255)
a = Target.Row
ecolumn = Worksheets("Form2").Cells(a, Columns.count).End(xlToLeft).Column
Range(Cells(a, 2), Cells(a, 7)).Copy
wks.Activate
wks.Range("B12").Select
ActiveSheet.Paste
With Selection
.Font.Size = 13
.Font.Name = "Arial"
.WrapText = True
.EntireRow.RowHeight = 27
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlVAlignCenter
.ColumnWidth = 33
.Interior.Color = RGB(255, 255, 255)
End With
Range(Cells(a, 8), Cells(a, ecolumn)).Copy
wks.Activate
wks.Range("B16").Select
wks.Range("B16").PasteSpecial Transpose:=True
''ActiveSheet.PasteSpecial
With Selection
.Font.Size = 13
.Font.Name = "Arial"
.WrapText = True
.EntireRow.RowHeight = 27
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlVAlignCenter
.ColumnWidth = 33
.Interior.Color = RGB(255, 255, 203)
End With
End If
If Worksheets("Form").ChartObjects.count > 0 Then Worksheets("Form").ChartObjects.Delete
Worksheets("Form").Range("D17").Interior.Color = RGB(255, 255, 255)
Worksheets("Form").Range("D17:D18").ClearContents
Application.Run "Sheet5.Range_End_Method"
Application.Goto (ActiveWorkbook.Sheets("Form").Range("C15"))
Application.ScreenUpdating = True
End Sub
The purpose of the code is to double click on any cell from A43 to (A and lastrow) and copy the items of the same row to the sheet named "Form". With the code above, i wanted the double click event to be functioning only for the A43 up to A and lastrow range and on the rest of the cells do nothing if double clicked any of them. However, the range A43 to A and lastrow works with the result that i want, but for the rest of the range defined, if i double click on any cell, the sheet Form is activated without copying any cells. If i define a fixed range like A1:R42 this works and the double click does nothing. If i define a dynamic range using lastrow parameter this does not work. Im i doing something wrong?
Any help appreciated.
Bookmarks