Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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
Vba 如何将列表中的项目添加到工作表中的单元格_Vba_Excel - Fatal编程技术网

Vba 如何将列表中的项目添加到工作表中的单元格

Vba 如何将列表中的项目添加到工作表中的单元格,vba,excel,Vba,Excel,我正在尝试将列表中的项目添加到Excel工作表中的某些行。 我试着这样做: Dim Rand As Long Dim ws As Worksheet Set ws = Worksheets("Necmontage") Rand = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row Range(ws.Cells(Rand, 1), ws.Cells(Rand + necesar.ListCount - 1, 1)).Merge ws.Cells

我正在尝试将列表中的项目添加到Excel工作表中的某些行。 我试着这样做:

Dim Rand As Long
Dim ws As Worksheet
Set ws = Worksheets("Necmontage")
Rand = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

Range(ws.Cells(Rand, 1), ws.Cells(Rand + necesar.ListCount - 1, 1)).Merge
ws.Cells(Rand, 1) = "K"

Range(ws.Cells(Rand, 2), ws.Cells(Rand + necesar.ListCount - 1, 2)).Merge
ws.Cells(Rand, 2) = "Montage"

Range(ws.Cells(Rand, 3), ws.Cells(Rand + necesar.ListCount - 1, 3)).Merge
ws.Cells(Rand, 3) = comanda.Caption

Dim i As Integer
i = 0
Do While i = necesar.ListCount - 1
    ws.Cells(Rand + i, 4) = necesar.List(i, 0)
    i = i + 1
Loop
End Sub

它添加我想要的所有值,除了列表中的值(我在循环时这样做)。我不知道为什么,但它不需要这些值。你知道这个问题吗?

你的代码中的意思是:

Do While i <= necesar.ListCount - 1 'instead of =
    ws.Cells(Rand + i, 4) = necesar.List(i, 0)
    i = i + 1
Loop

我来的时候做是的,非常感谢。。。我用一个For改变了时间,它成功了。。。我不知道是什么问题。。。好。。它没有给我任何错误,这就是为什么我没有使用调试模式。很高兴它终于起作用了。调试模式非常有用(特别是在vba中,您可以一步一步地执行并获取或设置变量值),即使您没有得到错误(只要您实际上没有得到预期的结果)。