VBA Get one or more links from web (from cells)












-1














I need this for my job. Someone wrote us a macro. This macro contains a module that take links from cells and download the files.
However. Problem is that it must be 2 rows or more that contain links.
This is nonsense for me/us as we often just download one link/file = only 1 row.



So the code must be able to handle a single row and multiple rows.



I can code a bit HTML and PHP, but that's quite long time ago.



I understand that the error "Subscript out of range" (= ext = buf(UBound(buf)) )
is because of the array. Or the way the array is being handled. But that's it.



To be honest I have not enough time to learn VBA to a point to fix this. I also only have access to these files at work...and here at work...I have to work lol.



So, help would be highly appreciated.



Sub DownloadFilefromWeb()
Dim strSavePath As String
Dim URL As String, ext As String
Dim buf, ret As Long
Dim fi As String
Dim lrow5 As Long
Dim path As String

Call Clear_All_Files_And_SubFolders_In_Folder
lrow5 = Range("A2").End(xlDown).Row
Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"

j = 1
For i = 2 To lrow5
fi = Worksheets("Link").Range("A" & i).Value
URL = Worksheets("Link").Range("G" & i).Value
buf = Split(URL, ".")
ext = buf(UBound(buf))
'MsgBox ActiveWorkbook.Path
strSavePath = ActiveWorkbook.path & "Backup" & fi & "," & j & "." & ext
ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
j = j + 1
'If ret = 0 Then
' MsgBox "Download has been succeed!"
'Else
' MsgBox "Error"
'End If

Next i
MsgBox ("Download Completed")
End Sub


Edit:



Screenshot of the excel sheet layout










share|improve this question





























    -1














    I need this for my job. Someone wrote us a macro. This macro contains a module that take links from cells and download the files.
    However. Problem is that it must be 2 rows or more that contain links.
    This is nonsense for me/us as we often just download one link/file = only 1 row.



    So the code must be able to handle a single row and multiple rows.



    I can code a bit HTML and PHP, but that's quite long time ago.



    I understand that the error "Subscript out of range" (= ext = buf(UBound(buf)) )
    is because of the array. Or the way the array is being handled. But that's it.



    To be honest I have not enough time to learn VBA to a point to fix this. I also only have access to these files at work...and here at work...I have to work lol.



    So, help would be highly appreciated.



    Sub DownloadFilefromWeb()
    Dim strSavePath As String
    Dim URL As String, ext As String
    Dim buf, ret As Long
    Dim fi As String
    Dim lrow5 As Long
    Dim path As String

    Call Clear_All_Files_And_SubFolders_In_Folder
    lrow5 = Range("A2").End(xlDown).Row
    Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"

    j = 1
    For i = 2 To lrow5
    fi = Worksheets("Link").Range("A" & i).Value
    URL = Worksheets("Link").Range("G" & i).Value
    buf = Split(URL, ".")
    ext = buf(UBound(buf))
    'MsgBox ActiveWorkbook.Path
    strSavePath = ActiveWorkbook.path & "Backup" & fi & "," & j & "." & ext
    ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
    j = j + 1
    'If ret = 0 Then
    ' MsgBox "Download has been succeed!"
    'Else
    ' MsgBox "Error"
    'End If

    Next i
    MsgBox ("Download Completed")
    End Sub


    Edit:



    Screenshot of the excel sheet layout










    share|improve this question



























      -1












      -1








      -1







      I need this for my job. Someone wrote us a macro. This macro contains a module that take links from cells and download the files.
      However. Problem is that it must be 2 rows or more that contain links.
      This is nonsense for me/us as we often just download one link/file = only 1 row.



      So the code must be able to handle a single row and multiple rows.



      I can code a bit HTML and PHP, but that's quite long time ago.



      I understand that the error "Subscript out of range" (= ext = buf(UBound(buf)) )
      is because of the array. Or the way the array is being handled. But that's it.



      To be honest I have not enough time to learn VBA to a point to fix this. I also only have access to these files at work...and here at work...I have to work lol.



      So, help would be highly appreciated.



      Sub DownloadFilefromWeb()
      Dim strSavePath As String
      Dim URL As String, ext As String
      Dim buf, ret As Long
      Dim fi As String
      Dim lrow5 As Long
      Dim path As String

      Call Clear_All_Files_And_SubFolders_In_Folder
      lrow5 = Range("A2").End(xlDown).Row
      Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"

      j = 1
      For i = 2 To lrow5
      fi = Worksheets("Link").Range("A" & i).Value
      URL = Worksheets("Link").Range("G" & i).Value
      buf = Split(URL, ".")
      ext = buf(UBound(buf))
      'MsgBox ActiveWorkbook.Path
      strSavePath = ActiveWorkbook.path & "Backup" & fi & "," & j & "." & ext
      ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
      j = j + 1
      'If ret = 0 Then
      ' MsgBox "Download has been succeed!"
      'Else
      ' MsgBox "Error"
      'End If

      Next i
      MsgBox ("Download Completed")
      End Sub


      Edit:



      Screenshot of the excel sheet layout










      share|improve this question















      I need this for my job. Someone wrote us a macro. This macro contains a module that take links from cells and download the files.
      However. Problem is that it must be 2 rows or more that contain links.
      This is nonsense for me/us as we often just download one link/file = only 1 row.



      So the code must be able to handle a single row and multiple rows.



      I can code a bit HTML and PHP, but that's quite long time ago.



      I understand that the error "Subscript out of range" (= ext = buf(UBound(buf)) )
      is because of the array. Or the way the array is being handled. But that's it.



      To be honest I have not enough time to learn VBA to a point to fix this. I also only have access to these files at work...and here at work...I have to work lol.



      So, help would be highly appreciated.



      Sub DownloadFilefromWeb()
      Dim strSavePath As String
      Dim URL As String, ext As String
      Dim buf, ret As Long
      Dim fi As String
      Dim lrow5 As Long
      Dim path As String

      Call Clear_All_Files_And_SubFolders_In_Folder
      lrow5 = Range("A2").End(xlDown).Row
      Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"

      j = 1
      For i = 2 To lrow5
      fi = Worksheets("Link").Range("A" & i).Value
      URL = Worksheets("Link").Range("G" & i).Value
      buf = Split(URL, ".")
      ext = buf(UBound(buf))
      'MsgBox ActiveWorkbook.Path
      strSavePath = ActiveWorkbook.path & "Backup" & fi & "," & j & "." & ext
      ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
      j = j + 1
      'If ret = 0 Then
      ' MsgBox "Download has been succeed!"
      'Else
      ' MsgBox "Error"
      'End If

      Next i
      MsgBox ("Download Completed")
      End Sub


      Edit:



      Screenshot of the excel sheet layout







      excel vba excel-vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 13:40







      Alex

















      asked Nov 23 '18 at 11:05









      AlexAlex

      32




      32
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Hard to say without knowing/seeing the layout of the sheet.



          I'll guess/assume that row 1 of the Links worksheet contains headers, and that the data itself (that you want to loop through) begins from row 2.



          Option Explicit

          Sub DownloadFilefromWeb()
          Dim strSavePath As String
          Dim URL As String
          Dim ret As Long
          Dim Filename As String
          Dim fileExtension As String

          Call Clear_All_Files_And_SubFolders_In_Folder

          With Worksheets("Link")
          Dim lastRow As Long
          lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

          .Range("G2:G" & lastRow).Formula = "=GetURL(E2)"

          Dim fileCount As Long
          fileCount = 1

          Dim rowIndex As Long
          For rowIndex = 2 To lastRow
          Filename = .Range("A" & rowIndex).Value
          URL = .Range("G" & rowIndex).Value
          fileExtension = VBA.Strings.Mid$(URL, VBA.Strings.InStrRev(URL, ".", -1, vbBinaryCompare))

          strSavePath = .Parent.path & "Backup" & Filename & "," & fileCount & fileExtension
          ret = URLDownloadToFile(0, URL, strSavePath, 0, 0) ' <- Don't seem to do anything with this value. Maybe include a MsgBox alert if it returns a non-zero value.

          fileCount = fileCount + 1
          Next rowIndex
          End With

          MsgBox ("Download Completed")
          End Sub


          Main difference is that lastRow is assigned working from the sheet's last row upward (previously it was downward from row 2, meaning it could never be only row 2 i.e. one row of data).






          share|improve this answer





















          • HI. Thank you. I've edited my orignal post and added a screenshot on the layout
            – Alex
            Nov 23 '18 at 13:42










          • @Alex, from what I can see, my assumption/guess was correct. When you get a chance at work, try the code and see if it does what you need.
            – chillin
            Nov 23 '18 at 13:49










          • Ahh hell yeah. Your code works.Thanks a lot mate :)
            – Alex
            Nov 23 '18 at 13:52





















          0














          lrow5 = Range("A2").End(xlDown).Row


          This gets the number of rows from the current workbook and worksheet. Then in the loop:



          For i = 2 To lrow5


          it starts at the second row. If you want it to start at the first row (and if there is only one row), then change his to:



          For i = 1 To lrow5





          Note: what I don't understand in this code is the line:

          Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"


          It seems this sets all of the hyperlinks to the URL of cell E2, i.e. to the same URL.



          The GetURL function is a custom function. See http://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel






          share|improve this answer





















          • Hi. Thanks for the quick reply. I've added a screenshot on my original post. What you suggested, I've tried already. But it gives me the same Error '9' Subscript out of range The part you don't understand is, it takes the Link from that cell and copies it to E2 (E3, E4, E5 etc.) I am not sure why it does so. As said, I guess the guy who made this macro, just copy&pasted stuff together.
            – Alex
            Nov 23 '18 at 13:48










          • User chillin below got the solution. Thank you anyways :)
            – Alex
            Nov 23 '18 at 13:53











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445510%2fvba-get-one-or-more-links-from-web-from-cells%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Hard to say without knowing/seeing the layout of the sheet.



          I'll guess/assume that row 1 of the Links worksheet contains headers, and that the data itself (that you want to loop through) begins from row 2.



          Option Explicit

          Sub DownloadFilefromWeb()
          Dim strSavePath As String
          Dim URL As String
          Dim ret As Long
          Dim Filename As String
          Dim fileExtension As String

          Call Clear_All_Files_And_SubFolders_In_Folder

          With Worksheets("Link")
          Dim lastRow As Long
          lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

          .Range("G2:G" & lastRow).Formula = "=GetURL(E2)"

          Dim fileCount As Long
          fileCount = 1

          Dim rowIndex As Long
          For rowIndex = 2 To lastRow
          Filename = .Range("A" & rowIndex).Value
          URL = .Range("G" & rowIndex).Value
          fileExtension = VBA.Strings.Mid$(URL, VBA.Strings.InStrRev(URL, ".", -1, vbBinaryCompare))

          strSavePath = .Parent.path & "Backup" & Filename & "," & fileCount & fileExtension
          ret = URLDownloadToFile(0, URL, strSavePath, 0, 0) ' <- Don't seem to do anything with this value. Maybe include a MsgBox alert if it returns a non-zero value.

          fileCount = fileCount + 1
          Next rowIndex
          End With

          MsgBox ("Download Completed")
          End Sub


          Main difference is that lastRow is assigned working from the sheet's last row upward (previously it was downward from row 2, meaning it could never be only row 2 i.e. one row of data).






          share|improve this answer





















          • HI. Thank you. I've edited my orignal post and added a screenshot on the layout
            – Alex
            Nov 23 '18 at 13:42










          • @Alex, from what I can see, my assumption/guess was correct. When you get a chance at work, try the code and see if it does what you need.
            – chillin
            Nov 23 '18 at 13:49










          • Ahh hell yeah. Your code works.Thanks a lot mate :)
            – Alex
            Nov 23 '18 at 13:52


















          0














          Hard to say without knowing/seeing the layout of the sheet.



          I'll guess/assume that row 1 of the Links worksheet contains headers, and that the data itself (that you want to loop through) begins from row 2.



          Option Explicit

          Sub DownloadFilefromWeb()
          Dim strSavePath As String
          Dim URL As String
          Dim ret As Long
          Dim Filename As String
          Dim fileExtension As String

          Call Clear_All_Files_And_SubFolders_In_Folder

          With Worksheets("Link")
          Dim lastRow As Long
          lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

          .Range("G2:G" & lastRow).Formula = "=GetURL(E2)"

          Dim fileCount As Long
          fileCount = 1

          Dim rowIndex As Long
          For rowIndex = 2 To lastRow
          Filename = .Range("A" & rowIndex).Value
          URL = .Range("G" & rowIndex).Value
          fileExtension = VBA.Strings.Mid$(URL, VBA.Strings.InStrRev(URL, ".", -1, vbBinaryCompare))

          strSavePath = .Parent.path & "Backup" & Filename & "," & fileCount & fileExtension
          ret = URLDownloadToFile(0, URL, strSavePath, 0, 0) ' <- Don't seem to do anything with this value. Maybe include a MsgBox alert if it returns a non-zero value.

          fileCount = fileCount + 1
          Next rowIndex
          End With

          MsgBox ("Download Completed")
          End Sub


          Main difference is that lastRow is assigned working from the sheet's last row upward (previously it was downward from row 2, meaning it could never be only row 2 i.e. one row of data).






          share|improve this answer





















          • HI. Thank you. I've edited my orignal post and added a screenshot on the layout
            – Alex
            Nov 23 '18 at 13:42










          • @Alex, from what I can see, my assumption/guess was correct. When you get a chance at work, try the code and see if it does what you need.
            – chillin
            Nov 23 '18 at 13:49










          • Ahh hell yeah. Your code works.Thanks a lot mate :)
            – Alex
            Nov 23 '18 at 13:52
















          0












          0








          0






          Hard to say without knowing/seeing the layout of the sheet.



          I'll guess/assume that row 1 of the Links worksheet contains headers, and that the data itself (that you want to loop through) begins from row 2.



          Option Explicit

          Sub DownloadFilefromWeb()
          Dim strSavePath As String
          Dim URL As String
          Dim ret As Long
          Dim Filename As String
          Dim fileExtension As String

          Call Clear_All_Files_And_SubFolders_In_Folder

          With Worksheets("Link")
          Dim lastRow As Long
          lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

          .Range("G2:G" & lastRow).Formula = "=GetURL(E2)"

          Dim fileCount As Long
          fileCount = 1

          Dim rowIndex As Long
          For rowIndex = 2 To lastRow
          Filename = .Range("A" & rowIndex).Value
          URL = .Range("G" & rowIndex).Value
          fileExtension = VBA.Strings.Mid$(URL, VBA.Strings.InStrRev(URL, ".", -1, vbBinaryCompare))

          strSavePath = .Parent.path & "Backup" & Filename & "," & fileCount & fileExtension
          ret = URLDownloadToFile(0, URL, strSavePath, 0, 0) ' <- Don't seem to do anything with this value. Maybe include a MsgBox alert if it returns a non-zero value.

          fileCount = fileCount + 1
          Next rowIndex
          End With

          MsgBox ("Download Completed")
          End Sub


          Main difference is that lastRow is assigned working from the sheet's last row upward (previously it was downward from row 2, meaning it could never be only row 2 i.e. one row of data).






          share|improve this answer












          Hard to say without knowing/seeing the layout of the sheet.



          I'll guess/assume that row 1 of the Links worksheet contains headers, and that the data itself (that you want to loop through) begins from row 2.



          Option Explicit

          Sub DownloadFilefromWeb()
          Dim strSavePath As String
          Dim URL As String
          Dim ret As Long
          Dim Filename As String
          Dim fileExtension As String

          Call Clear_All_Files_And_SubFolders_In_Folder

          With Worksheets("Link")
          Dim lastRow As Long
          lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

          .Range("G2:G" & lastRow).Formula = "=GetURL(E2)"

          Dim fileCount As Long
          fileCount = 1

          Dim rowIndex As Long
          For rowIndex = 2 To lastRow
          Filename = .Range("A" & rowIndex).Value
          URL = .Range("G" & rowIndex).Value
          fileExtension = VBA.Strings.Mid$(URL, VBA.Strings.InStrRev(URL, ".", -1, vbBinaryCompare))

          strSavePath = .Parent.path & "Backup" & Filename & "," & fileCount & fileExtension
          ret = URLDownloadToFile(0, URL, strSavePath, 0, 0) ' <- Don't seem to do anything with this value. Maybe include a MsgBox alert if it returns a non-zero value.

          fileCount = fileCount + 1
          Next rowIndex
          End With

          MsgBox ("Download Completed")
          End Sub


          Main difference is that lastRow is assigned working from the sheet's last row upward (previously it was downward from row 2, meaning it could never be only row 2 i.e. one row of data).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 12:10









          chillinchillin

          1,369134




          1,369134












          • HI. Thank you. I've edited my orignal post and added a screenshot on the layout
            – Alex
            Nov 23 '18 at 13:42










          • @Alex, from what I can see, my assumption/guess was correct. When you get a chance at work, try the code and see if it does what you need.
            – chillin
            Nov 23 '18 at 13:49










          • Ahh hell yeah. Your code works.Thanks a lot mate :)
            – Alex
            Nov 23 '18 at 13:52




















          • HI. Thank you. I've edited my orignal post and added a screenshot on the layout
            – Alex
            Nov 23 '18 at 13:42










          • @Alex, from what I can see, my assumption/guess was correct. When you get a chance at work, try the code and see if it does what you need.
            – chillin
            Nov 23 '18 at 13:49










          • Ahh hell yeah. Your code works.Thanks a lot mate :)
            – Alex
            Nov 23 '18 at 13:52


















          HI. Thank you. I've edited my orignal post and added a screenshot on the layout
          – Alex
          Nov 23 '18 at 13:42




          HI. Thank you. I've edited my orignal post and added a screenshot on the layout
          – Alex
          Nov 23 '18 at 13:42












          @Alex, from what I can see, my assumption/guess was correct. When you get a chance at work, try the code and see if it does what you need.
          – chillin
          Nov 23 '18 at 13:49




          @Alex, from what I can see, my assumption/guess was correct. When you get a chance at work, try the code and see if it does what you need.
          – chillin
          Nov 23 '18 at 13:49












          Ahh hell yeah. Your code works.Thanks a lot mate :)
          – Alex
          Nov 23 '18 at 13:52






          Ahh hell yeah. Your code works.Thanks a lot mate :)
          – Alex
          Nov 23 '18 at 13:52















          0














          lrow5 = Range("A2").End(xlDown).Row


          This gets the number of rows from the current workbook and worksheet. Then in the loop:



          For i = 2 To lrow5


          it starts at the second row. If you want it to start at the first row (and if there is only one row), then change his to:



          For i = 1 To lrow5





          Note: what I don't understand in this code is the line:

          Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"


          It seems this sets all of the hyperlinks to the URL of cell E2, i.e. to the same URL.



          The GetURL function is a custom function. See http://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel






          share|improve this answer





















          • Hi. Thanks for the quick reply. I've added a screenshot on my original post. What you suggested, I've tried already. But it gives me the same Error '9' Subscript out of range The part you don't understand is, it takes the Link from that cell and copies it to E2 (E3, E4, E5 etc.) I am not sure why it does so. As said, I guess the guy who made this macro, just copy&pasted stuff together.
            – Alex
            Nov 23 '18 at 13:48










          • User chillin below got the solution. Thank you anyways :)
            – Alex
            Nov 23 '18 at 13:53
















          0














          lrow5 = Range("A2").End(xlDown).Row


          This gets the number of rows from the current workbook and worksheet. Then in the loop:



          For i = 2 To lrow5


          it starts at the second row. If you want it to start at the first row (and if there is only one row), then change his to:



          For i = 1 To lrow5





          Note: what I don't understand in this code is the line:

          Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"


          It seems this sets all of the hyperlinks to the URL of cell E2, i.e. to the same URL.



          The GetURL function is a custom function. See http://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel






          share|improve this answer





















          • Hi. Thanks for the quick reply. I've added a screenshot on my original post. What you suggested, I've tried already. But it gives me the same Error '9' Subscript out of range The part you don't understand is, it takes the Link from that cell and copies it to E2 (E3, E4, E5 etc.) I am not sure why it does so. As said, I guess the guy who made this macro, just copy&pasted stuff together.
            – Alex
            Nov 23 '18 at 13:48










          • User chillin below got the solution. Thank you anyways :)
            – Alex
            Nov 23 '18 at 13:53














          0












          0








          0






          lrow5 = Range("A2").End(xlDown).Row


          This gets the number of rows from the current workbook and worksheet. Then in the loop:



          For i = 2 To lrow5


          it starts at the second row. If you want it to start at the first row (and if there is only one row), then change his to:



          For i = 1 To lrow5





          Note: what I don't understand in this code is the line:

          Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"


          It seems this sets all of the hyperlinks to the URL of cell E2, i.e. to the same URL.



          The GetURL function is a custom function. See http://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel






          share|improve this answer












          lrow5 = Range("A2").End(xlDown).Row


          This gets the number of rows from the current workbook and worksheet. Then in the loop:



          For i = 2 To lrow5


          it starts at the second row. If you want it to start at the first row (and if there is only one row), then change his to:



          For i = 1 To lrow5





          Note: what I don't understand in this code is the line:

          Worksheets("Link").Range("G2:G" & lrow5).Formula = "=GetURL(E2)"


          It seems this sets all of the hyperlinks to the URL of cell E2, i.e. to the same URL.



          The GetURL function is a custom function. See http://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 11:28









          Paul OgilviePaul Ogilvie

          17.5k21234




          17.5k21234












          • Hi. Thanks for the quick reply. I've added a screenshot on my original post. What you suggested, I've tried already. But it gives me the same Error '9' Subscript out of range The part you don't understand is, it takes the Link from that cell and copies it to E2 (E3, E4, E5 etc.) I am not sure why it does so. As said, I guess the guy who made this macro, just copy&pasted stuff together.
            – Alex
            Nov 23 '18 at 13:48










          • User chillin below got the solution. Thank you anyways :)
            – Alex
            Nov 23 '18 at 13:53


















          • Hi. Thanks for the quick reply. I've added a screenshot on my original post. What you suggested, I've tried already. But it gives me the same Error '9' Subscript out of range The part you don't understand is, it takes the Link from that cell and copies it to E2 (E3, E4, E5 etc.) I am not sure why it does so. As said, I guess the guy who made this macro, just copy&pasted stuff together.
            – Alex
            Nov 23 '18 at 13:48










          • User chillin below got the solution. Thank you anyways :)
            – Alex
            Nov 23 '18 at 13:53
















          Hi. Thanks for the quick reply. I've added a screenshot on my original post. What you suggested, I've tried already. But it gives me the same Error '9' Subscript out of range The part you don't understand is, it takes the Link from that cell and copies it to E2 (E3, E4, E5 etc.) I am not sure why it does so. As said, I guess the guy who made this macro, just copy&pasted stuff together.
          – Alex
          Nov 23 '18 at 13:48




          Hi. Thanks for the quick reply. I've added a screenshot on my original post. What you suggested, I've tried already. But it gives me the same Error '9' Subscript out of range The part you don't understand is, it takes the Link from that cell and copies it to E2 (E3, E4, E5 etc.) I am not sure why it does so. As said, I guess the guy who made this macro, just copy&pasted stuff together.
          – Alex
          Nov 23 '18 at 13:48












          User chillin below got the solution. Thank you anyways :)
          – Alex
          Nov 23 '18 at 13:53




          User chillin below got the solution. Thank you anyways :)
          – Alex
          Nov 23 '18 at 13:53


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445510%2fvba-get-one-or-more-links-from-web-from-cells%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Trompette piccolo

          Slow SSRS Report in dynamic grouping and multiple parameters

          Simon Yates (cyclisme)