Offset the result

  • Thread starter Thread starter Jock
  • Start date Start date
Hi,

With L5 as the active cell try this

Range("L1").Value = ActiveCell.Offset(, -1) + 50

Mike
 
OOPS,

that should have been

Range("L1").Value = ActiveCell.Offset(-1) + 50

Mike
 
Hi Mike,

I have placed your code within a Private Sub DoubleClick (see below). This
works until the user double cluicks a cell with no data in it when the code
stops working until the spreadsheet is closed down and opened again.
Can something be put in to ignore double clicks in empty cells?
And is there such a thing as a "single click" alternative?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("k6:k30")) Is Nothing Then
With Target
If .Value <> "" Then
Range("L2").Value = ActiveCell.Offset(0, -2) + 50
Application.EnableEvents = True
End If
End With
End If
End Sub


Thanks.
 
Hi,

You were disabling events at the wrong time

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Not Intersect(Target, Me.Range("k6:k30")) Is Nothing Then
With Target
If .Value <> "" Then
Application.EnableEvents = False
Range("L2").Value = ActiveCell.Offset(0, -2) + 50
Application.EnableEvents = True
End If
End With
End If
End Sub

Mike
 
Thats better!
Quick question, could the GotFocus event be used in this scenario rather
than the
BeforeDoubleClick? Users will moan.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top