Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 用循环在VBA中填充列表_Excel_Vba - Fatal编程技术网

Excel 用循环在VBA中填充列表

Excel 用循环在VBA中填充列表,excel,vba,Excel,Vba,我在填充ValidateList时遇到问题。这是我的密码: For i = 2 To letzteZeile Do While ws.Cells(i, 3).Text = ws.Cells(i + 1 + j, 3).Text j = j + 1 Loop If j > 0 Then dvList = ws.Cells(i, 1) Do While k < j k = k + 1 dvLis

我在填充ValidateList时遇到问题。这是我的密码:

For i = 2 To letzteZeile

Do While ws.Cells(i, 3).Text = ws.Cells(i + 1 + j, 3).Text

        j = j + 1
Loop


If j > 0 Then

    dvList = ws.Cells(i, 1)

Do While k < j

              k = k + 1
              dvList = dvList + ", " + ws.Cells(i + k, 1)
Loop


With ws.Cells(i, "FT").Validation

    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=dvList
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True

End With

End If

Next i
i=2至LetztZeile的

Do While ws.Cells(i,3).Text=ws.Cells(i+1+j,3).Text
j=j+1
环
如果j>0,则
dvList=ws.Cells(i,1)
当k
那我想做什么呢

我想浏览几行,查找重复项,然后将属于重复项的数据放在一个下拉菜单中

我收集“dvList”(字符串)中的数据,并将其放入FT中的列表中

但不知何故,我收集的字符串在开头有一个撇号,而我的下拉菜单中只有带“'Data1,Data2,Data3”的字段

你对如何解决我的问题有什么想法吗

(我不是100%确定,如果这种下拉菜单是正确的。) (最后,如果可能的话,我想把其他工作表的链接放到下拉菜单中。)


提前谢谢

这不是解决所有问题的完整方案,只是下一步:

1.更换:

dvList = dvList + ", " + ws.Cells(i + k, 1)
与:

(我们删除了与逗号相关的额外空白)

2.检查语句前面的dvList,方法包括:

MsgBox dvList

不幸的是,除了缺少的空格之外,这并没有改变任何东西(;MsgBox说什么?)我只是重新格式化了整个表,现在没有更多的撇号了O.O MsgBox说“数据,数据1,数据2”
MsgBox dvList