Help!!!Please with addr=Target.Address

  • Hi ALL,


    I posed this question yesterday and thought that it was resolved, however, the solution opened the door to new problems.


    My project incorporates about a half dozen or more columns (each column with at least 240 rows) which run a macro using the find method when the user double-clicks a cell.


    Currently, I'm running this code:


    >>>>>>>>>>>>>>>>>>>>>
    IPrivate Sub Worksheet_BeforeDoubleClick( _
    ByVal target As Excel.Range, _
    Cancel As Boolean)
    Dim addr As String
    addr = target.Address
    If addr = "$A$13" Then
    End If
    If addr = "$A$14" Then
    End If
    If addr = "$A$15" Then
    End If
    and so on................
    End Sub
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    and it works spendidly. The problem with this code is that it includes a reference for each cell where I want this "Double-Click" event to occur, thus it uses too much memory.


    I recently experimented with variations of this code that would be more efficient and reduced the amount of memory required to run the procedure. The code included the following:


    code:
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>CaIPrivate Sub Worksheet_BeforeDoubleClick( _
    ByVal target As Excel.Range, _
    Cancel As Boolean)
    Dim addr As String
    addr = target.Address
    If addr >= "$A$13" and addr <= "$A$100" Then
    Call 'FindRoutine'
    End If
    End Sub
    &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
    The above code produces inconsistent results, sometimes it works and other times not at all.


    I also tried the following and at first I thought I had my problem resolved, but then I notice that while my routine would work in column "A", it would work before cell "$A$13" even though my control statement clearly defines the range where it should be activate.


    code:
    &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
    Private Sub Worksheet_BeforeDoubleClick( _
    ByVal target As Excel.Range, _
    Cancel As Boolean)
    Dim addr As String
    addr = target.Address
    Select Case addr
    case "$A$13" To "$A$100"
    Call 'FindRoutine'
    End Select End Sub
    &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;


    Furthermore, I have tried to define my range with:
    Case Is >="$A$13"
    again the results are inconsistent.


    Any help onthis will be greatly appreciated.


    Chris

  • Your second code example has no chance of working for numerous reason. The number one reason is that your Case statement makes no sense.
    <pre&gt;Case "A13" To "A100" </pre&gt;


    makes no sense in this instance because "A13" and "A100" are treated as string values and not as ranges. An analogy would be that it would be just as useful as doing a search on a spreadsheet with literally the criteria "Aardvark" to "Zebra" to return all of the animals listed on the sheet.


    Anyway, here's my stab at your code. It's not necessarily pretty, but the problem sounds as though the complete solution is going to be pretty ugly anyway. :D



    Can I ask you what version of Excel you are using. This is the second piece of code today that I've seen "Target As Excel.Range" in the arguments for a worksheet event. (Rather than just "Target As Range")


    Hope this helps

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!