gallopingant
New Member
- Joined
- Aug 19, 2020
- Messages
- 9
- Office Version
- 365
- Platform
- MacOS
I have a For Each loop that only partially works. The idea is that when the submit button is clicked, hyperlinks are created with the value of the cell appended to the end of the hyperlink. Something like a unique ID that takes you to a specific website for that particular identifier. The problem is that the loop only returns the last value, though when I add a MsgBox and have it return that, it returns all the values.
The cells are across multiple rows and columns, as indicated before and I'd like the hyperlinks to be generated in the same manner.
What would cause this? Here is the relevant portion of the code. There can only be up to a pre-determined number of codes entered. There can be less, but not more, which is why I through the If statement in there.
The cells are across multiple rows and columns, as indicated before and I'd like the hyperlinks to be generated in the same manner.
What would cause this? Here is the relevant portion of the code. There can only be up to a pre-determined number of codes entered. There can be less, but not more, which is why I through the If statement in there.
VBA Code:
Dim c As Range
Dim rng As Range
Set rng = Worksheets("Form").Range("H1:I4")
For Each c In rng
If c > 0 Then
ThisWorkbook.Worksheets("Form").Hyperlinks.Add Range("J1:K4"), Address:="website.url?ID=" & c.Value, TextToDisplay:="Product Number " & c.Value
MsgBox (c.Value)
End If
Next c