文本框值存储在一个循环的Excel工作表

Dim RI As Integer Dim CI As Integer Dim X As Integer Dim texts() As Variant ActiveCell.Offset(1, 0).Select RI = ActiveCell.Row ActiveSheet.Cells(RI, 1).Select CI = ActiveCell.Column texts = Array(Text5.Text, Text6.Text, Text7.Text, Text8.Text, Text9.Text,Text10.Text, Text11.Text, Text12.Text, Text13.Text, Text14.Text, Text15.Text, Text16.Text, Text17.Text, Text18.Text, Text19.Text) For CI = 2 To 16 For X = 0 To UBound(texts) ActiveSheet.Cells(RI, CI).Value = texts(X) Next X Next CI 

亲爱的朋友们,我必须从15个文本框中的texttext到1ext19.text的值,并将其存储在一个从B列到P的Excel表格中。当我按照上面的代码,它只返回所有单元格中的text19.text的行。 请build议我的朋友…

不需要循环。 使用.Resize 。 这是一个例子

 ' '~~> Rest of the code ' texts = Array("1", "2", "3", "4", "5", "6", "7", "8", _ "9", "10", "11", "12", "13", "14", "15") '~~> Not needed 'For CI = 2 To 16 'For X = 0 To UBound(texts) 'ActiveSheet.Cells(RI, CI).Value = texts(X) 'Next X 'Next CI ActiveSheet.Cells(RI, CI).Resize(, 15).Value = texts 

编辑

如果你仍然想使用循环,然后像这样使用它

 ' '~~> Rest of the code ' texts = Array("1", "2", "3", "4", "5", "6", "7", "8", _ "9", "10", "11", "12", "13", "14", "15") j = 2 '~~> Not needed For X = 0 To UBound(texts) ActiveSheet.Cells(RI, j).Value = texts(X) j = j + 1 Next X 

在你的代码中,列没有被正确地递增。