PC Review


Reply
Thread Tools Rate Thread

BeforeDoubleClick Event not working

 
 
Ayo
Guest
Posts: n/a
 
      10th Mar 2010
I have this BeforeDoubleClick event, below, that I am trying to run.
Everything was working fine yesterday now, it just jumps from the "If" to
the "End If" statements. I can't figure out what's going on.
Any ideas?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Dim errorWS As Worksheet, siteWS As Worksheet
Dim i As Integer, rw As Integer

Set siteWS = Worksheets("Site Milestone Dates")
Set errorWS = Worksheets("Error_MarketList")
errorWS_lastRow = errorWS.Range("A65536").End(xlUp).Row

If Target.Address() >= "$A$5" Or Target.Address() <= "$A$" &
errorWS_lastRow Then
Application.EnableEvents = False
Application.ScreenUpdating = False

siteWS.Range("C4").Value = Target.Value
siteWS.Range("E4").Value = UCase(Target.Offset(0, 1).Value)

rw = 7
For i = 2 To 23 Step 2
siteWS.Range("E" & rw).Value = Target.Offset(0, i).Value
siteWS.Range("G" & rw).Value = Target.Offset(0, i + 1).Value
rw = rw + 2
Next i

rw = 7
For i = 24 To 45 Step 2
siteWS.Range("M" & rw).Value = Target.Offset(0, i).Value
siteWS.Range("O" & rw).Value = Target.Offset(0, i + 1).Value
rw = rw + 2
Next i

Application.EnableEvents = True
Application.ScreenUpdating = True
End If
siteWS.Select
End Sub
 
Reply With Quote
 
 
 
 
Ryan H
Guest
Posts: n/a
 
      10th Mar 2010
It seems to me your If...Then statement is setup wrong. I assume you are
wanting the code inside the If...Then statement to run if the user double
clicks any cell in Col.A that is greater that 4, right? If so, change your
If...Then statement from

If Target.Address() >= "$A$5" Or Target.Address() <= "$A$" &
errorWS_lastRow Then

to this...

If Not Intersect(Target, errorWS.Range("A5:A" & errorWS_LastRow)) Is Nothing
Then

Plus, don't forget to declare your variables. errorWS_LastRow should be
declared as Long.

Plus, use this code to find you last cell with data. This will work for all
versions of Excel.

errorWS_LastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row

Hope this helps! If so, let me know, click "YES" below.

--
Cheers,
Ryan


"Ayo" wrote:

> I have this BeforeDoubleClick event, below, that I am trying to run.
> Everything was working fine yesterday now, it just jumps from the "If" to
> the "End If" statements. I can't figure out what's going on.
> Any ideas?
>
> Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
> Boolean)
> Dim errorWS As Worksheet, siteWS As Worksheet
> Dim i As Integer, rw As Integer
>
> Set siteWS = Worksheets("Site Milestone Dates")
> Set errorWS = Worksheets("Error_MarketList")
> errorWS_lastRow = errorWS.Range("A65536").End(xlUp).Row
>
> If Target.Address() >= "$A$5" Or Target.Address() <= "$A$" &
> errorWS_lastRow Then
> Application.EnableEvents = False
> Application.ScreenUpdating = False
>
> siteWS.Range("C4").Value = Target.Value
> siteWS.Range("E4").Value = UCase(Target.Offset(0, 1).Value)
>
> rw = 7
> For i = 2 To 23 Step 2
> siteWS.Range("E" & rw).Value = Target.Offset(0, i).Value
> siteWS.Range("G" & rw).Value = Target.Offset(0, i + 1).Value
> rw = rw + 2
> Next i
>
> rw = 7
> For i = 24 To 45 Step 2
> siteWS.Range("M" & rw).Value = Target.Offset(0, i).Value
> siteWS.Range("O" & rw).Value = Target.Offset(0, i + 1).Value
> rw = rw + 2
> Next i
>
> Application.EnableEvents = True
> Application.ScreenUpdating = True
> End If
> siteWS.Select
> End Sub

 
Reply With Quote
 
Ayo
Guest
Posts: n/a
 
      10th Mar 2010
Thanks Ryan. Works great so far.

"Ryan H" wrote:

> It seems to me your If...Then statement is setup wrong. I assume you are
> wanting the code inside the If...Then statement to run if the user double
> clicks any cell in Col.A that is greater that 4, right? If so, change your
> If...Then statement from
>
> If Target.Address() >= "$A$5" Or Target.Address() <= "$A$" &
> errorWS_lastRow Then
>
> to this...
>
> If Not Intersect(Target, errorWS.Range("A5:A" & errorWS_LastRow)) Is Nothing
> Then
>
> Plus, don't forget to declare your variables. errorWS_LastRow should be
> declared as Long.
>
> Plus, use this code to find you last cell with data. This will work for all
> versions of Excel.
>
> errorWS_LastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row
>
> Hope this helps! If so, let me know, click "YES" below.
>
> --
> Cheers,
> Ryan
>
>
> "Ayo" wrote:
>
> > I have this BeforeDoubleClick event, below, that I am trying to run.
> > Everything was working fine yesterday now, it just jumps from the "If" to
> > the "End If" statements. I can't figure out what's going on.
> > Any ideas?
> >
> > Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
> > Boolean)
> > Dim errorWS As Worksheet, siteWS As Worksheet
> > Dim i As Integer, rw As Integer
> >
> > Set siteWS = Worksheets("Site Milestone Dates")
> > Set errorWS = Worksheets("Error_MarketList")
> > errorWS_lastRow = errorWS.Range("A65536").End(xlUp).Row
> >
> > If Target.Address() >= "$A$5" Or Target.Address() <= "$A$" &
> > errorWS_lastRow Then
> > Application.EnableEvents = False
> > Application.ScreenUpdating = False
> >
> > siteWS.Range("C4").Value = Target.Value
> > siteWS.Range("E4").Value = UCase(Target.Offset(0, 1).Value)
> >
> > rw = 7
> > For i = 2 To 23 Step 2
> > siteWS.Range("E" & rw).Value = Target.Offset(0, i).Value
> > siteWS.Range("G" & rw).Value = Target.Offset(0, i + 1).Value
> > rw = rw + 2
> > Next i
> >
> > rw = 7
> > For i = 24 To 45 Step 2
> > siteWS.Range("M" & rw).Value = Target.Offset(0, i).Value
> > siteWS.Range("O" & rw).Value = Target.Offset(0, i + 1).Value
> > rw = rw + 2
> > Next i
> >
> > Application.EnableEvents = True
> > Application.ScreenUpdating = True
> > End If
> > siteWS.Select
> > End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid protected cell warning on BeforeDoubleClick WS event Matt Microsoft Excel Programming 2 15th Apr 2010 11:59 AM
Help With BeforeDoubleClick jean Microsoft Excel Programming 3 19th Mar 2008 07:02 PM
BeforeDoubleClick Stefi Microsoft Excel Programming 7 20th Dec 2007 10:13 AM
i want to know about "beforedoubleclick" event =?Utf-8?B?Z29wYWwgc2luZ2g=?= Microsoft Excel Programming 1 21st Mar 2006 03:31 PM
BeforeDoubleClick Cancel=True not working =?Utf-8?B?UmVnZ2ll?= Microsoft Excel Programming 1 20th Sep 2005 03:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:01 AM.