答案 0 :(得分:0)
尝试一下:
sub jain()
Dim ws1 as Worksheet, ws2 as Worksheet, xrow1 as long, xrow2 as long, xcol as Int, ID as string
set ws1 = Worksheets("Sheet1")
set ws2 = Worksheets("Sheet2")
xrow1 = 2
xrow2 = 2
xcol = 3
do until ws1.Cells(xrow1, 2) = ""
do until ws2.Cells(xrow2, 2) = ""
ID = ws2.Cells(xrow2, 1).value
if InStr(1, ws1.Cells(xrow1, 2), ID) > 0 Then
ws1.Cells(xrow1, xcol).value = ws2.Cells(xrow2, 1).value
xcol = xcol + 1
else:
End if
xrow2 = xrow2 + 1
loop
xrow2 = 2
xcol = 3
loop
end sub
基本上,这将循环遍历每个单元并检查是否存在id匹配。如果为1,则InStr函数的值将为1,从而使if触发器将超链接从sheet2复制到sheet1中ID列右侧的单元格中。
我这样做是假设在sheet1上,TC ID列是第二列,在sheet2中的超链接列是第二列(并且该工作表具有标题),并且TC ID右侧的所有单元格sheet1上的列为空白。如果这些假设中的任何一个错误,我都需要更改代码中的值以使其正常工作。
我没有对此进行测试,因此如果您遇到错误,请通知我,我可以解决。