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

我试图将列表中的项目添加到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 

它添加了我想要的所有值,除了列表中的值(我在While循环中)。 我不知道为什么,但是并没有采取这些价值观。 有关这个问题的任何想法?

你的意思是在你的代码中:

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

顺便说一句,你可以在debugging模式下看到,如果程序运行在你想要的地方,在Do While行上放一个断点。