如何在用户窗体的特定单元格上设置我的输入数据?

How to set up my input data on a specific cell in Userform?

我想从一个特定的单元格开始添加数据并在另一个单元格停止。从 I7:I10 到 T7:T10。 但我想从用户表单输入数据。但是每当我输入数据时,它都会说我在 Cell 16,000 上。

我有两个数据集,用户窗体中的一个选项卡运行良好,它会按行输入数据。但是对于另一个选项卡,我希望它在下一列输入它。顺便说一句,我有低于I7的数据。但是有些区域是空白的,有些区域有数据。 Userform 中的一个选项卡将转到一个名为 Employee 的单独 sheet,另一个将转到 TestCal。

Private Sub CBSave_Click()

Dim lrEmp as Long
Dim lrCal as Long

'This part work fine
lrEmp = Sheets("Employee").Range("A" & Rows.Count).End(xlUp).Row
With Sheets("Employee")
    .Cells(lrEmp + 1, "A").Value = tbEmpID.Text
    .Cells(lrEmp + 1, "B").Value = tbName.Text
    .Cells(lrEmp + 1, "C").Value = tbLast.Text
End With

'This is the part I am having trouble with
lcCal = Sheets("TestCal").Range("Sales") .End(xlToLeft).Column
With Sheets("TestCal")
     .Cells(lrCal, "I").Value = tbApple.Text
     .Cells(lrCal + 1, "I").Value = tbOrange.Text
     .Cells(lrCal + 2, "I").Value = tbBanana.Text
End With

End Sub

我想我的第一列设置有误,我该如何设置下一个数据条目将在右侧的位置。现在,出于某种原因,数据条目一直被输入到 16,000 个单元格。

**忘了说了,tbApple、tbOrange、tbBanana都在同一列。我想像那样与他们一起获得下一专栏。

我希望我说得有道理。谢谢。

如果您要查找上次使用的列右侧的列,请尝试以下操作:两张表,一张名为 Testcal,一张名为 Main。

Private Sub TestCal()
lccal = Sheets("TestCal").Cells(1, Columns.Count).End(xlToLeft).Column + 1
Sheets("Main").Cells(1, 1) = lccal
End Sub

此 returns 您在 Testcal 中选择的任何行的最右侧使用的列右侧的列。

不确定 7 到 10 的来源,也许 7 是 header?

'This is the part I am having trouble with
lcCal = Sheets("TestCal").Cells(7,columns.count).End(xlToLeft).Column + 1
With Sheets("TestCal")
     .Cells(8, lcCal).Value = tbApple.Text
     .Cells(9, lcCal).Value = tbOrange.Text
     .Cells(10, lcCal).Value = tbBanana.Text
End With

End Sub