excel如何通过VBA按照日期自动赋值(2)

亲们,在表格名称为“datebase”的表格中,假设今天是2018-10-10,我如果只在 销量 列中输入数据(从B4列开始输入,直到B2000),怎样通过 VBA 向右边 10(就是2018-10-10,我把月和日分开了) 列赋值 销量 列中输入的数据同理,如果今天是2018-10-11,怎样将 今日销量 数据赋值到 11 列中一直到2018-10-31,怎样赋值到 31 列中...非常感谢

Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
        For i = 1 To .Count
            If .Cells(i).Row >= 4 And .Cells(i).Row <= 2000 And .Cells(i).Column = 2 Then
                .Cells(i).Offset(0, 2 + Day(Now)) = .Cells(i)
            End If
        Next i
    End With
End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-10-10
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim tr, tc, k
tr = Target.Row
tc = Target.Column
If tr >= 4 And tc = 2 Then
Y = Date
Set r1 = Rows(1).Find(Y, , , 1)
If Not r1 Is Nothing Then
k = r1.Column
Cells(tr, tc + k - 2) = Cells(tr, tc)
End If
End If
End Sub
第2个回答  2018-10-10
写代码可实现,要有文件,说清楚要求!
相似回答
大家正在搜