+ Reply to Thread
Results 1 to 12 of 12

If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

  1. #1
    Registered User
    Join Date
    05-20-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    6

    If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Hi

    I forgive my ignorance I am new to VBA and have ben trying to cut and paste various bits of code together to achieve my goal

    end goal =

    double click a cell in a column from which an embedded file (outlook message) is opened

    The column contains 100's of entries but these boil down to 5 variants (each variant has its own email)

    I can get the code to open up a single object but not to open up the object related to the value in the column

    any help would be much appreciated
    Thanks



    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Dim Object99 As String

    Object99 = Application.WorksheetFunction.VLookup(Objective, Worksheets("email").Range("b:c"), 2, False)
    'MsgBox Object1



    If Not Intersect(Target, Range("AD:AD")) Is Nothing Then

    Application.ScreenUpdating = False

    Sheets("email").OLEObjects("Object99").Verb

    Me.Activate

    Application.ScreenUpdating = True

    Cancel = True

    End If

    End Sub

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Dim Object99 As String
    Not sure why you quoted Object99 in double quotes which will be considered as Text entry instead of variable value.

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    05-20-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    6

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Hi Apologies this was an error on my part

    I have removed the "" but it still doen snot work??

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Object99 = Application.WorksheetFunction.VLookup(Objective, Worksheets("email").Range("b:c"), 2, False)
    Objective refers to what?

  5. #5
    Registered User
    Join Date
    05-20-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    6

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    im sorry again, it was part of some code I copied and pasted...it does not mean anything

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Quote Originally Posted by wideboy View Post
    im sorry again, it was part of some code I copied and pasted...it does not mean anything
    Okay, try this...

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-20-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    6

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    :D

    I feel rather inept...thank you sir!

    so would the IF statement need to preceed the DIM statements?

    Thanks mate!

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Quote Originally Posted by wideboy View Post
    IF statement need to preceed the DIM statements?
    No...

    Using Dim Object99 As String will tell excel to allocate 10 bytes of memory for Object99 variable.

    So excel will allocate 10 bytes for Object99 whenever double click event occurs on any cell. It is waste of memory and unnecessarily this code will run on all double clicks.

    But your actual intention is to allocate memory for Object99 variable when the double click occurs in AD column only. So using the variable declaration inside the If() will avoid the unnecessary memory allocation and unncessary vlookup process.

    Hope it's clear now.

    PS: Also note that I changed Objective to Target.Value. Target refers to double clicked cell (Event Range/Cell)

  9. #9
    Registered User
    Join Date
    05-20-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    6

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Thanks, why the 2 lines of screen updating? one true and one false?

    Screen updating refers to the onscreen following of the macro right?

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Quote Originally Posted by wideboy View Post
    why the 2 lines of screen updating? one true and one false?
    When we don't want the users to get notified about the changes/screen movements then before doing those actions we have to turn off the screen updating. When we finished all work then we have to turn it ON. Because screen updating is an application setting which affects all macro codes if it is turned off.

    Also turning off screen updating will increase the speed of the macro since excel can silently do all it's stuffs without showing all the actions to the users.

  11. #11
    Registered User
    Join Date
    05-20-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    6

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    Thanks mate, you are a legend...have a great weekend!

  12. #12
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: If Not Intersect(Target, Range("AD:AD")) Is Nothing Then,,,,VLOOKUP??

    You're welcome and have a nice weekend to you too...

    Also, thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] If Target.Cells(1).Address = Range("$B$5": ..(?)..)
    By Marcin4111 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2015, 06:57 AM
  2. [SOLVED] Can i use 2 different "Worksheet_Change(ByVal Target As Range)" on a sheet?
    By Viktor86HUN in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2015, 08:01 AM
  3. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  4. [SOLVED] Multiple "ByVal Target As Range"
    By batchy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-08-2013, 02:50 PM
  5. Replies: 3
    Last Post: 07-30-2013, 01:38 AM
  6. Getting "..object _worksheet failed..." error with intersect for cell and named range.
    By cool1_boy1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2013, 04:17 PM
  7. Need help creating VBA looping code in "Worksheet_Change(ByVal Target As Range)"
    By jimredfield in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2012, 03:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1