+ Reply to Thread
Results 1 to 10 of 10

VBA scan list of codes in A and return a different code based on match's in column S

  1. #1
    Registered User
    Join Date
    02-16-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    ProPlus 2016 - Excel
    Posts
    5

    Question VBA scan list of codes in A and return a different code based on match's in column S

    Hi all,

    First time using this forum, or any for that matter.
    Apologies if I am doing this wrong or if this is in the wrong section, please advise if so and I can change.

    Basically I have a ever expanding list of part numbers in in Column A, and I want to return a location code or likely many location codes in Column S.
    I have compiled a list in my macro BaseDoc (macro enabled file which I run in the background to execute various macros on each delivery order).

    So what I am looking for help with is creating a macro to scan the all populated cells in column A for code eg(1545214587) and if it is present to input (L1R6|L3R9|L2R1) into the corresponding cell in column S.
    I have got it to work but only if I scan each cell in column A manually below is the code I used for that, however I now realize (after 2 weeks) that this will take many many lifetimes to input the same search for each cell in column A and then repeat over for the roughly 4000 part numbers one by one.
    Below is an example of what I have been using. Can I loop this easily for any populated cells in column A?

    Sub Part_Number_And_Location_Lookup()

    If Range("A2").Value = 1545214587 Then Range("S2").Value = "L1R6|L3R9|L2R1"

    End Sub


    Any ideas on how I can test each cell in the column for the part number and return the value if it is present and just ignore it if not?
    Or am I going about this task in completely the wrong way and is there a better way?

    Thanks in advance
    Brian.

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Do you perchance have a list of part numbers with the data you want to enter? Code can be written to search for values that are in a list and populate the relative value. Please provide a sample file as per the yellow banner above that has both the lists and the parts you need updated.

  3. #3
    Registered User
    Join Date
    02-16-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    ProPlus 2016 - Excel
    Posts
    5

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Here is a sample list of the code lists, I will get a sample of the file I want to run the Macro on and upload as fast as possible

    Thank you
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-16-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    ProPlus 2016 - Excel
    Posts
    5

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Here is the sample of the sheets I will want to run the macro on, the layout as in the part number being in column A and the Location codes needing to be in column S will never change.
    Thank you so much for any help you can offer

    Brian
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Can the list of codes be another sheet with in master list file?

  6. #6
    Registered User
    Join Date
    02-16-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    ProPlus 2016 - Excel
    Posts
    5

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Yea I don't see why not, my idea was to have them on a sheet within my BaseDoc as there is a massive list of codes (5000+) and it is ever expanding, also the locations change from time to time.
    It will take me a long time to populate the list and it will have to be amended from time to time too, that is why I think it would be best to have a list of part numbers and corresponding location codes as although it will take a long time I can add to it bit by bit and change the locations if necessary.
    Am I approaching the task wrong or is that the best way to achieve the goal?

  7. #7
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Your approach sounds reasonable. I combined the two sample sheets into one file below, and the code applies to the file. If you need it to process faster there are some more things we can do. Test this for now.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-16-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    ProPlus 2016 - Excel
    Posts
    5

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Oh sorry I misunderstood your question before.
    No they will be separate as the destination sheet (where I need the location inputted into column S) is created every day.
    Sorry

  9. #9
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    Here you go, The code will ask you to open a destination sheet. Let me know if you have questions.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA scan list of codes in A and return a different code based on match's in column S

    No need of vba.

    1) Open both workbooks.
    2) Enter Sheet1!S2 of Sample2.xlsx
    =IFERROR(VLOOKUP(A2,[sample.xlsx]Sheet1!A:B,2,FALSE),"")
    then copy down.
    3) close Sample.xlsx then formula should automatically update the link with the full path.

+ 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] VBA to scan a worksheet for a specific value, and return the header and first column value
    By sboivin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-14-2018, 04:47 PM
  2. [SOLVED] Convert Y Codes from one column to another based on Unique Codes
    By ashishmehra2010 in forum Excel General
    Replies: 2
    Last Post: 10-06-2015, 09:49 PM
  3. Macro to scan a column and return a value
    By orlex in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-27-2015, 09:58 AM
  4. Scan a row for text; return row and column header info
    By Kronote in forum Excel General
    Replies: 5
    Last Post: 06-02-2013, 06:43 PM
  5. Replies: 2
    Last Post: 10-08-2012, 12:49 PM
  6. scan data, find max value of column, return single record on other worksheet
    By virtualnoob in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-26-2012, 11:26 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