Vba 要存储在带有循环的excel工作表中的文本框值
亲爱的朋友们:,Vba 要存储在带有循环的excel工作表中的文本框值,vba,excel,Vba,Excel,亲爱的朋友们:, 我必须从15个文本框(从text5.text到1ext19.text)中获取值,并将其存储在从B列到P列的excel工作表中。当我遵循上述代码时,它只返回行所有单元格中的text19.text。请推荐我的朋友……无需循环。使用.Resize。这里有一个例子 Dim RI As Integer Dim CI As Integer Dim X As Integer Dim texts() As Variant ActiveCell.Offset(1, 0).Select RI =
我必须从15个文本框(从text5.text到1ext19.text)中获取值,并将其存储在从B列到P列的excel工作表中。当我遵循上述代码时,它只返回行所有单元格中的text19.text。请推荐我的朋友……无需循环。使用
.Resize
。这里有一个例子
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
编辑
如果你仍然想使用循环,那么就这样使用它
'
'~~> 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
在您的代码中,列没有正确递增。++为消除循环,非常感谢Siddharth Rout。。。它工作!!!
'
'~~> 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