我刚开始使用Excel,遇到了这个问题。
我希望我的用户表单能够根据用户选择的日期自动填充列中的动态范围。当单击"create“按钮时,同时在工作表的一列上填充日期,在旁边的另一列上填充月份名称,这取决于编码的日期。你觉得这有可能吗?我们将非常感谢您的努力。谢谢!
Private Sub CommandButton1_Click()
If Week <> "" Then
Dim ws As Worksheet
Dim LR1 As Long
Dim LR3 As Long
Dim LR4 As Long
Set ws = ThisWorkbook.Sheets("Sheet1")
' get the last row from columns that has a value
LR1 = ws.range("A" & ws.Rows.Count).End(xlUp).Row
LR3 = ws.range("C" & ws.Rows.Count).End(xlUp).Row + 1
LR4 = ws.range("D" & ws.Rows.Count).End(xlUp).Row + 1
' use the last row to determine how far down to extend the formula
ws.range("D" & LR4 & ":D" & LR1).Value = Me.Week.Value
ws.range("C" & LR3 & ":C" & LR1).Value = Me.DTPicker1.Value
Else
MsgBox "Please fill all fields!"
End If
Unload Me
End Sub

发布于 2016-06-14 11:35:52
若要在B列中添加月份名称,请将以下内容添加到代码中:
Dim LR2 As Long
' ...
LR2 = ws.Range("B" & ws.Rows.Count).End(xlUp).Row + 1
' ...
ws.Range("B" & LR2 & ":B" & LR1).FormulaR1C1 = "=TEXT(R[0]C[1], ""mmm"")"这实际上将在B列中插入一个公式,该列表示它旁边单元格的月份名称。
发布于 2016-06-14 11:05:03
我不确定我是否正确地理解了这种情况,但也许您可以用".formula =application.worksheetfunction“(”=month(.)“)填充第二栏
https://stackoverflow.com/questions/37809881
复制相似问题