0

i would like to add range value to my link but it is doesn't work some one can help how can i add range value to the link please? thanks a lot

    Dim iLink
    Dim myUrl
    Dim Number
    
    i = 7
    Number= Range("D" & i).Value
    myUrl = "https://www.google.com/Number"

    While Range("D" & i).Value <> ""
    iLink = myUrl & Range("D" & i).Value

    ActiveSheet.Hyperlinks.Add _
    Anchor:=Range("D" & i).Offset(, 1), _
    Address:=iLink
    i = i + 1
    Wend

3
  • What does doesn't work mean? An error? Wrong output? Commented Jun 17, 2022 at 18:39
  • i mean no error but the link opened is google.com instead of google.com/123 Commented Jun 17, 2022 at 18:45
  • 1
    Change myUrl = "https://www.google.com/Number" to myUrl = "https://www.google.com/. Commented Jun 17, 2022 at 18:47

1 Answer 1

3

You can do it like this

myUrl = "https://www.google.com/" & Number

Because you enclosed your variable 'Number' inside double quotes, vba counted it as a string, not a variable.

Sign up to request clarification or add additional context in comments.

3 Comments

iLink = myUrl & Range("D" & i).Value would duplicate.
@findwindow yeah that's correct, but what if he wants it to duplicate it 😅, our both answers are correct depending on if he wants it to duplicate it or not.
Yea, his comment says google/123 but clearly he wants google/123/123

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.