我正在创建一个自定义网址列(用于导入Mailchimp)并且遇到了一些对我来说太棘手的事情。
我正在构建一个从其他单元格中获取元素的url列。除了一个(“角色”)变量之外,几乎所有url部分都是相同的。以下是最终网址将如何显示粗体部分是从电子表格输入的变量的位置:
http://domain.com/的 varPath /零件名称= varEmployee &安培;客户端ID = varClient &安培;作用= varRole
url列填充A列中相同数量的行。下面是电子表格中相关列/单元格的列表,以供澄清:
Column A = email of all employees completing form
Cell B2 = first name (always using first entry for "varEmployee" in the url)
Cell C2 = last name (same as above)
Column D = varClient (stays the same)
Column E = varRole (THIS IS THE TRICKY ONE since I need to get the changing value)
cell I2 = varPath
“varEmployee”变量总是一样(B2 + C2) varClient和varPath也是如此,因为我们只需要第二行(在标题下)的值。但是,“varRole”变量将随每行而变化,因为A列中的每个电子邮件都与列E中的不同角色相关联。我不知道如何将该值添加到url字符串中,因为它会不断变化。如果有人有任何想法,我的代码如下。提前致谢。
Dim lngLastRow As Long
Dim varURL As String
Dim varSurvey As String
Dim varPart As String
Dim varEmployee As String
Dim varRole As String
Dim varClient As String
varURL = "https://domain.com/" + Range("I2").Text
varSurvey = Range("I2").Value
varPart = "?PartName="
varEmployee = Range("B2") + " " + Range("C2")
varRole = "&Role=" + Range("E2")
varClient = "&ClientID=" + Range("D2").Text
varFinal = (varURL & varSurvey & varPart & varEmployee & "&ClientID=" & varClient)
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("F2:F" & lngLastRow).Value = voxFinal
答案 0 :(得分:0)
好的,在看到Rob的回复之后,我又读了几篇“for next”帖子,我改变了方法并编写了一个略有不同的脚本。这就是我最终拼凑起来似乎有用的东西:
Sub buildURL()
'
' buildURL Macro
'
'
Dim N As Long, i As Long, j As Long
Dim voxURL As String
Dim varSurvey As String
Dim varPart As String
Dim varEmployee As String
Dim varRole As String
Dim varClient As String
varURL = "https://domain.com/" + Range("I2").Text
varSurvey = Range("I2").Value
varPart = "?PartName="
varEmployee = Range("B2") + " " + Range("C2")
varRole = "&Role="
varClient = "&ClientID=" + Range("D2").Text
varFinal = (varURL & varSurvey & varPart & varEmployee & varClient & varRole)
N = Cells(Rows.Count, "A").End(xlUp).Row
j = 2
For i = 2 To N
If Not IsEmpty(Range("A" & i).Value) Then
Cells(j, "F").Value = voxFinal & Cells(i, "E").Value
j = j + 1
End If
Next i
End Sub