+ Reply to Thread
Results 1 to 11 of 11

Lookup / VBA help

  1. #1
    Registered User
    Join Date
    12-29-2015
    Location
    North Carolina, USA
    MS-Off Ver
    2007
    Posts
    17

    Lookup / VBA help

    This should be a fairly easy fix, but I am racking my brain how to figure this one out and I hope one of you geniuses can help me out.

    I have 4 columns of numbers
    Numbers 1-30 are in column AH(15-44)
    Numbers 31-60 are in column AL(15-44)
    Numbers 61-90 are in column AQ(15-44)
    Numbers 91-120 are in column AV(15-44)
    I would like to look through these numbers and match the number that is entered in a merged cell (AI11-AM11). When it finds the match, I would like to put "END" beside the number that matches.

    Example: if I enter 20 in AI11, I would like it to return "END" in AH34

    Thanks in advance for your help. This will help me out so much

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Lookup / VBA help

    Try this macro

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 12-29-2015 at 09:01 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-29-2015
    Location
    North Carolina, USA
    MS-Off Ver
    2007
    Posts
    17

    Re: Lookup / VBA help

    Thanks. This is helpful. Can you help me modify it a little farther?

    When the value in AI11:AM11 changes, I would like the worksheet to automatically find the new "END" and remove the old one.

    Example if the end changes from 20 to 30, I would like the end that was next to 20 removed and inserted next to the 30.

    I appreciate all your help

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Lookup / VBA help

    Hi

    Why bother with a macro when there's a perfectly straighforward Excel function you can use.
    e.g. in AI15 copied down

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    12-29-2015
    Location
    North Carolina, USA
    MS-Off Ver
    2007
    Posts
    17

    Re: Lookup / VBA help

    Some times I'll have to enter text at other numbers besides the end. Entering text will remove the formula. This is why I was trying to go macro based so I wouldn't lose the formula whenever I put text in.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Lookup / VBA help

    Right click on the sheet name at the bottom of excel

    select view code

    Paste this code into the macro module

    Close the macro module

    change AH15

    Please Login or Register  to view this content.

    This version might be better:


    Private Sub Worksheet_Change(ByVal Target As Range)



    Set rnglook = Union(Range("AH15:AH44"), Range("AL15:AL44"), Range("AQ15:AQ44"), Range("AV15:AV44"))

    If Not Intersect(Target, rnglook) Is Nothing Then
    With rnglook

    Set rngFind = .Find(Range("AI11").Value, .Cells(1, 1), LookIn:=xlValues, lookat:=xlWhole)
    If Not rngFind Is Nothing Then
    rnglook.Offset(0, 1).Value = ""
    rngFind.Offset(0, 1).Value = "End"
    End If
    End With

    End If
    End Sub
    Last edited by mehmetcik; 12-31-2015 at 07:56 AM.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Lookup / VBA help

    Quote Originally Posted by Mitas View Post
    Some times I'll have to enter text at other numbers besides the end. Entering text will remove the formula. This is why I was trying to go macro based so I wouldn't lose the formula whenever I put text in.
    It always helps if you mention all conditions/restrictions in your first post so that we avoid wasting time. This is the first mention that you also want to be able to enter text. So please explain with some examples where you might want to enter text and what happens if that cell with text also meets the condition for satisfying your 'End' text requirement? Which takes precedence your text or the word End?

  8. #8
    Registered User
    Join Date
    12-29-2015
    Location
    North Carolina, USA
    MS-Off Ver
    2007
    Posts
    17

    Re: Lookup / VBA help

    Thanks for the help. It got me most of the way there and I was able to figure out the rest to get it where I wanted.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Lookup / VBA help

    Following Richards comments

    I realise The modified code is useless for you.


    Try this instead:

    Private Sub Worksheet_Change(ByVal Target As Range)



    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Lookup / VBA help

    Duplicate Deleted.

  11. #11
    Registered User
    Join Date
    12-29-2015
    Location
    North Carolina, USA
    MS-Off Ver
    2007
    Posts
    17

    Re: Lookup / VBA help

    mehmetcik,

    I have copied the code and ran it. when I do I get a compile error: invalid or unqualified reference. The error message highlights the second .cells. I have indicated where it is highlighting on the code below in red.

    Set rnglook = Union(Range("AH15:AH44"), Range("AL15:AL44"), Range("AQ15:AQ44"), Range("AV15:AV44"))

    If Not Intersect(Target, rnglook) Is Nothing Then
    With rnglook

    Set rngFind = .Find(Range("End").Value, .Cells(1, 1), LookIn:=xlValues, lookat:=xlWhole)
    If Not rngFind Is Nothing Then
    rngFind.Offset(0, 1).Value = ""
    End If
    End With

    Set rngFind = .Find(Range("AI11").Value, .Cells(1, 1), LookIn:=xlValues, lookat:=xlWhole)
    If Not rngFind Is Nothing Then
    rngFind.Offset(0, 1).Value = "End"
    End If
    End With

    End If
    End Sub

+ 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. Two Lookup and Return (Lookup the column, then lookup the row)
    By Branbran10 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-05-2015, 04:55 PM
  2. Replies: 4
    Last Post: 05-19-2015, 08:42 PM
  3. Replies: 3
    Last Post: 04-08-2014, 03:11 AM
  4. Replies: 2
    Last Post: 05-19-2013, 08:46 AM
  5. Replies: 1
    Last Post: 11-07-2012, 01:57 PM
  6. Search lookup array to find lookup value contained within text string
    By Cookstein2 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-02-2011, 09:42 AM
  7. Replies: 7
    Last Post: 06-19-2011, 12:51 PM

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