使用数组并复制到下一个可用行只会给我第一个单元格中的数据(用户表单输入)
Using arrays and copying into next available row only gives me data in the first cell (user form input)
我正在制作一个 ERP 系统,我有一个有效但丑陋的代码可以满足我的要求。我只是第一次尝试使用数组,在使用它时,我只将第一个文本框输入到我的存档电子表格中,即使我还有 9 个文本框分配给该数组。有点难以解释,但更容易看出我在代码中尝试做什么。
我已经尝试将 nextRow 变量的 "B2" 更改为 "C2" 但它仍然只给我第一个文本框输入并将其粘贴到我的 nextRow 变量中首先提到的任何单元格中。
(此代码是在代码审查网站上提供给我的,但我也尝试对其进行了一些更改,但没有任何运气。
'Making the variable that stores the input from all 9 textboxes in the userform
Dim inputs As Variant
'Variabler for inputs
inputs = Array(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox10.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text)
'Declaring the variable for the next available row from B to J so I can copy the input from each textbox into the corresponding cell in the Archive worksheet.
Dim nextRowB As Range
Set nextRowB = Sheets("Arkiv").Range("C" & Rows.Count & ":J" & Rows.Count).End(xlUp).Offset(1, 0)
nextRowB.Value = inputs
不是将每个文本框输入复制到相应的单元格,而是仅将第一个文本框输入 (textbox1) 复制到下一个可用行的第一列,然后让其余的为空。
我期望此代码使用我在将不同文本框输入分配给数组时使用的相同顺序将每个文本框输入一直粘贴到 B 列中的下一个可用行,一直到 J。
可以这样试试
Dim inputs As Variant
inputs = Array(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox10.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text)
Dim nextRowB As Range
Set nextRowB = Sheets("Arkiv").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
nextRowB.Resize(1, UBound(inputs) + 1).Value = inputs
我正在制作一个 ERP 系统,我有一个有效但丑陋的代码可以满足我的要求。我只是第一次尝试使用数组,在使用它时,我只将第一个文本框输入到我的存档电子表格中,即使我还有 9 个文本框分配给该数组。有点难以解释,但更容易看出我在代码中尝试做什么。
我已经尝试将 nextRow 变量的 "B2" 更改为 "C2" 但它仍然只给我第一个文本框输入并将其粘贴到我的 nextRow 变量中首先提到的任何单元格中。
(此代码是在代码审查网站上提供给我的,但我也尝试对其进行了一些更改,但没有任何运气。
'Making the variable that stores the input from all 9 textboxes in the userform
Dim inputs As Variant
'Variabler for inputs
inputs = Array(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox10.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text)
'Declaring the variable for the next available row from B to J so I can copy the input from each textbox into the corresponding cell in the Archive worksheet.
Dim nextRowB As Range
Set nextRowB = Sheets("Arkiv").Range("C" & Rows.Count & ":J" & Rows.Count).End(xlUp).Offset(1, 0)
nextRowB.Value = inputs
不是将每个文本框输入复制到相应的单元格,而是仅将第一个文本框输入 (textbox1) 复制到下一个可用行的第一列,然后让其余的为空。
我期望此代码使用我在将不同文本框输入分配给数组时使用的相同顺序将每个文本框输入一直粘贴到 B 列中的下一个可用行,一直到 J。
可以这样试试
Dim inputs As Variant
inputs = Array(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox10.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text)
Dim nextRowB As Range
Set nextRowB = Sheets("Arkiv").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
nextRowB.Resize(1, UBound(inputs) + 1).Value = inputs