Is there any way similar to the python . format method for VBA in Excel?

Asked

Viewed 61 times

-3

In python using the . format for this:

users = ['profile1', 'profile2']

print("www.instagram.com/f{users[0]}/")

Would soon come out: www.instagram.com/profile1/

Is there any similar method in vba?

2 answers

1

All right with you?

I believe that what you are looking for would be something like the code below, that is, assign a value to a text variable and create a link using the value of this variable:

Sub Perfil()

Dim Usuario As String

Usuario = "perfil1"

ActiveSheet.Range("A1").Select

'Cria o link
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="https://www.instagram.com/" & Usuario


End Sub

In this code, an Instagram link is created using the user mentioned in the cell selected by the code (cell "A1").

I hope it helps!

1


I do not know how to pass the variable directly in the body of the string, VBA does not interpret so. You can concatenate the string + variable + string with the operator &

Sub exemplo()

Dim usuários As Variant

usuários = Array("pedro", "paulo")

Debug.Print "www.instagram.com/" & usuários(0) & "/"

Debug.Print "www.instagram.com/" & usuários(1) & "/"

End Sub

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.