+ Reply to Thread
Results 1 to 20 of 20

excel vba loop through values in a column and get hyperlinks from another sheet using Vloo

  1. #1
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    excel vba loop through values in a column and get hyperlinks from another sheet using Vloo

    Hi,

    I'd like to use excel vba to loop through values in a column and get hyperlinks from another sheet using Vlookup and use the original values in the column as the friendly name. Is this possible? I've tried the below code but only get Run-time error '1004': Unable to get the Vlookup property of the WorksheetFunction class. Is there anyway to get this to work?

    Sub Get_Links_From_Hidden_Tab_Using_VLOOKUP_and_Give_It_The_Original_ID_As_Friendly_Name()


    For Each xCell In Range("A:A")

    Dim x As Variant
    x = xCell.Value

    If xCell.Value <> "" Then

    ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=Application.WorksheetFunction.VLookup(x, Worksheets("Hidden").Range("A:O"), 15, 0), TextToDisplay:=xCell.Value

    End If

    Next xCell

    End Sub

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Maybe try:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Hi CheeseSandwich,

    Thanks very much! It works perfectly except for one issue. If there happens to be a blank/empty cell in the list that has no value (and this does happen with some of our lists that we're trying to add links to), the macro throws a Run-time error '13': Type mismatch.

    I'm wondering if the variable type for addr should changed from String to another type, maybe? Or do you know if this is another issue entirely? Just some way to handle blank cells and / or cells that have no match in the "Hidden" sheet?

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Maybe:
    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Hi CheeseSandwich,

    This works perfectly. Thanks so much!

  6. #6
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Hi CheeseSandwich,

    Sorry, I actually spoke too soon. I still get the mismatch error when there is a value in the cell list in the first sheet that has no match in the Hidden sheet...(the empty value issue has been fixed).

  7. #7
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Hmm ok try:
    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.
    It is counting to see if the value it is looking up exists in the lookup sheet

  8. #8
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Strange...no errors but now the macro does not generate any links at all for any of the cells in the list.

    Not sure if it's the Countif looking for a value greater than 0? I've tried to make it work if it doesn't equal "#N/A" which is what is returned when there's no match in the "Hidden" sheet, but no go.
    Last edited by dagda13; 01-27-2022 at 12:29 PM.

  9. #9
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Maybe try these instead:

    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.
    Last edited by CheeseSandwich; 01-27-2022 at 03:40 PM.

  10. #10
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    These both work perfectly. Can't thank you enough for all the time you've put in for helping me out with this. Very much appreciated!

  11. #11
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Yep, these are perfect! Thanks so much, again! Wish I could Add Reputation more than just once.

  12. #12
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    You are very welcome

  13. #13
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    I enjoy problem solving, it is the pickle in my sandwich...

  14. #14
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Hi,

    Just one thing that I've found...the macro does not make links for purely numerical values...ie., like some IDs in the list are just six digits "123456". These IDs also have links in the "Hidden" tab but the macro skips over these. It does make links for the alpha-numeric ID's, like "it_clml_01_enus". Just not sure what it skips the purely numberical IDs...

    Totally spitballing here but maybe because we were dealing the Strings before and the purely numerical ID's are Integers?
    Last edited by dagda13; 01-27-2022 at 04:43 PM.

  15. #15
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Tyr changing this line:
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    Last edited by CheeseSandwich; 01-27-2022 at 05:08 PM.

  16. #16
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Still only links for the alpha-numerics. Attached an image (with Integers with no links and alphanumerics with links)Attachment 765446

    Yeah I did some testing and it will only create a link if there are letters in the value (it will work with just letters as value, values with letters and numbers...it just will not work with only numbers).
    Last edited by dagda13; 01-27-2022 at 05:22 PM.

  17. #17
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Are you able to format the lookup column A in the hidden sheet as text?

  18. #18
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Yes, I've formatted both columns (column A in Sheet1 and Column A in "Hidden") as text (with the cstr change to the code) but still the numeric-only IDs do not have a links generated.

  19. #19
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Ahh I placed the Cstr part in the wrong place (I was trying to help from my mobile) it should have been on the TextToDisplay part of that line. I have also added a check so that it does not assign a hyperlink if it does not find the value in the Hidden tab.

    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    05-18-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    11

    Re: excel vba loop through values in a column and get hyperlinks from another sheet using

    Success! Works absolutely perfectly. Tried to give you more reputation but it won't let me. Earned it and then some. Thanks so much, again.

+ 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] Loop through column to add hyperlinks ignoring blank cells
    By ghostly1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-10-2020, 04:07 AM
  2. [SOLVED] Macro to filter column and copy rows to new sheet with loop for all unique values in colum
    By Gryphoune in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-24-2015, 09:15 AM
  3. Using Loop to copy different column values from a Source tab to 3 different Excel tabs
    By dipjyoti123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2013, 04:48 PM
  4. Loop through column and copy specific values to another sheet for calculations
    By caoexcel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2013, 02:49 PM
  5. Find Hyperlinks, Copy Hyperlinks to alternative sheet, print all hyperlinks
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 05:13 PM
  6. [SOLVED] Loop Through Column, Populate Values In Another Sheet With Matching Identifiers
    By aeg_paul in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-15-2013, 02:10 PM
  7. loop through values in listbox and search for them in excel sheet
    By longhorn23 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-29-2010, 08:32 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