公式自动填充日期列适用于 sheet 但不适用于表格
Formula auto fills date column works on sheet but not in the form
我正在使用公式在下一列中输入内容后立即自动填充日期。
=If(B9="","",IF(A9="",NOW(),B9))
完成此操作后,我将公式应用于单元格,直到第 48 行。现在,在源代码(参考屏幕截图)中输入的任何内容都会自动填充日期。很有魅力,一切都很好。
设计了一个用于输入数据减去日期的用户表单,因为使用了上述公式。应该工作,但事实并非如此。日期为 1/1/1900
。稍微偏离一个世纪 +18 年,没什么大不了的。
您可以在我用于数据输入的屏幕截图中看到的代码。最初我将 sheet 设置为最多 48 行。因为当使用 userform 时,数据在第 48 行之后进入 "only",因此 table 不断扩展。我已经删除了 48 之后的行很多次,以至于它不再有趣了。
现在 VBA 代码不知何故关闭或不完整,这让整个事情变得有趣。我该如何解决这个问题?
P.S。使用 Excel 2016
表单上添加数据按钮的代码。为此,数据不是从第 9 行 B 列开始填充。它从第 48 行之后开始。
Private Sub CommandButton1_Click()
Dim dcc As Long
Dim abc As Worksheet
Set abc = Worksheets("January2019")
dcc = Sheets("January2019").Range("A" & Rows.Count).End(xlUp).Row
With abc
.Cells(dcc + 1, 2).Value = Me.TextBox1.Value
.Cells(dcc + 1, 3).Value = Me.TextBox2.Value
.Cells(dcc + 1, 4).Value = Me.TextBox3.Value
.Cells(dcc + 1, 5).Value = Me.TextBox4.Value
.Cells(dcc + 1, 6).Value = Me.TextBox5.Value
End With
日期代码。
=If(B9="","",IF(A9="",NOW(),B9))
如果手动输入数据,日期会自动工作,但当使用用户表单时,日期输入为 1/1/1900,上面提到的输入是在第 48 行之后进行的。
我 hoping/aiming 使用此代码和用户表单的目的是:
在用户表单中没有日期选项。我在第 9 行添加了日期公式,然后将其拖到第 48 行。使用户表单减去日期字段,因为一旦输入数据,日期就会自动填充。并且,数据从第一个可用行 B9 开始填充。所以现在我迷路了,因为我不知道故障在哪里或发生了什么,这使得这个添加随机行并且日期很远。
您可以替换您的公式,只使用您当前的用户表单添加今天的日期。
Private Sub CommandButton1_Click()
Dim dcc As Long
Dim abc As Worksheet
Set abc = Worksheets("January2019")
dcc = Sheets("January2019").Range("A" & Rows.Count).End(xlUp).Row
With abc
.Cells(dcc + 1, 1).Value = Date
.Cells(dcc + 1, 2).Value = Me.TextBox1.Value
.Cells(dcc + 1, 3).Value = Me.TextBox2.Value
.Cells(dcc + 1, 4).Value = Me.TextBox3.Value
.Cells(dcc + 1, 5).Value = Me.TextBox4.Value
.Cells(dcc + 1, 6).Value = Me.TextBox5.Value
End With
您无需在用户表单中为要输入的日期添加 space。
...how to connect the drop down list from user form so that when month of february2019 is selected the sheet which is named february2019 gets the data...
这应该有效:
Dim abc As Worksheet
Set abc = Worksheets(me.ComboBox1.Value)
我正在使用公式在下一列中输入内容后立即自动填充日期。
=If(B9="","",IF(A9="",NOW(),B9))
完成此操作后,我将公式应用于单元格,直到第 48 行。现在,在源代码(参考屏幕截图)中输入的任何内容都会自动填充日期。很有魅力,一切都很好。
设计了一个用于输入数据减去日期的用户表单,因为使用了上述公式。应该工作,但事实并非如此。日期为 1/1/1900
。稍微偏离一个世纪 +18 年,没什么大不了的。
您可以在我用于数据输入的屏幕截图中看到的代码。最初我将 sheet 设置为最多 48 行。因为当使用 userform 时,数据在第 48 行之后进入 "only",因此 table 不断扩展。我已经删除了 48 之后的行很多次,以至于它不再有趣了。
现在 VBA 代码不知何故关闭或不完整,这让整个事情变得有趣。我该如何解决这个问题?
P.S。使用 Excel 2016
表单上添加数据按钮的代码。为此,数据不是从第 9 行 B 列开始填充。它从第 48 行之后开始。
Private Sub CommandButton1_Click()
Dim dcc As Long
Dim abc As Worksheet
Set abc = Worksheets("January2019")
dcc = Sheets("January2019").Range("A" & Rows.Count).End(xlUp).Row
With abc
.Cells(dcc + 1, 2).Value = Me.TextBox1.Value
.Cells(dcc + 1, 3).Value = Me.TextBox2.Value
.Cells(dcc + 1, 4).Value = Me.TextBox3.Value
.Cells(dcc + 1, 5).Value = Me.TextBox4.Value
.Cells(dcc + 1, 6).Value = Me.TextBox5.Value
End With
日期代码。
=If(B9="","",IF(A9="",NOW(),B9))
如果手动输入数据,日期会自动工作,但当使用用户表单时,日期输入为 1/1/1900,上面提到的输入是在第 48 行之后进行的。
我 hoping/aiming 使用此代码和用户表单的目的是:
在用户表单中没有日期选项。我在第 9 行添加了日期公式,然后将其拖到第 48 行。使用户表单减去日期字段,因为一旦输入数据,日期就会自动填充。并且,数据从第一个可用行 B9 开始填充。所以现在我迷路了,因为我不知道故障在哪里或发生了什么,这使得这个添加随机行并且日期很远。
您可以替换您的公式,只使用您当前的用户表单添加今天的日期。
Private Sub CommandButton1_Click()
Dim dcc As Long
Dim abc As Worksheet
Set abc = Worksheets("January2019")
dcc = Sheets("January2019").Range("A" & Rows.Count).End(xlUp).Row
With abc
.Cells(dcc + 1, 1).Value = Date
.Cells(dcc + 1, 2).Value = Me.TextBox1.Value
.Cells(dcc + 1, 3).Value = Me.TextBox2.Value
.Cells(dcc + 1, 4).Value = Me.TextBox3.Value
.Cells(dcc + 1, 5).Value = Me.TextBox4.Value
.Cells(dcc + 1, 6).Value = Me.TextBox5.Value
End With
您无需在用户表单中为要输入的日期添加 space。
...how to connect the drop down list from user form so that when month of february2019 is selected the sheet which is named february2019 gets the data...
这应该有效:
Dim abc As Worksheet
Set abc = Worksheets(me.ComboBox1.Value)