简体   繁体   中英

VB syntax error for concatenate and evaluate

I am trying to write a VB script that concatenates data together into a url string and then I want it to copy down into all the rows for that column. I've got the fill down code working okay but when I try to add the concatenate I keep getting a syntax error so I'm not sure what I'm doing wrong. I have tried two versions and they both give me syntax errors on the final line of script (right side):

Script Version 1:

Sub SetSurveyLink()

' SetSurveyLink Macro

Dim lngLastRow As Long
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("C3:C" & lngLastRow).Value = EVALUATE("https://domainname.com/survey/?PartName=" & 'Client List'!B1 & "&ClientID="&B2)
End Sub

Script Version 2:

Sub SetSurveyLink()

' SetSurveyLink Macro

Dim lngLastRow As Long

lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("C3:C" & lngLastRow).Value = CONCATENATE("https://domainname.com/survey/?PartName=",'Client List'!B1,"&ClientID=",B2)

End Sub

The 'concatenate' string gives me the correct value when used in a cell (ie not as part of a script) but I just can't get it to work in the script. See anything that I'm missing in my syntax?

THANK YOU!

Any double-quote marks within a string need to be escaped to be double double-quote marks so, if

"https://domainname.com/survey/?PartName=" & 'Client List'!B1 & "&ClientID="&B2

worked within Excel, it becomes

""https://domainname.com/survey/?PartName="" & 'Client List'!B1 & ""&ClientID=""&B2

and then you need to enclose that within double-quote marks to make it a string literal within VBA, ie

"""https://domainname.com/survey/?PartName="" & 'Client List'!B1 & ""&ClientID=""&B2"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM