VBA code to add current date in next cell

2019-08-02 06:38发布

问题:

I have below data (attached), which I have to add manually everyday. Now, I am trying to automate it.

  1. I would want to add current date in the next cell available (Ex : Cell E1)
  2. Second cell (E2), should get the return value of rows visible after autofilter from another Sheet named "Stock".

Please help me with these two codes.

回答1:

Sub main()
    With Range("A1").CurrentRegion
        .Offset(, .Columns.Count).Resize(2, 1) = Application.Transpose(Array(Date, Application.WorksheetFunction.Subtotal(103, Worksheets("Stock").UsedRange.Columns(1).SpecialCells(XlCellType.xlCellTypeVisible))))
    End With
End Sub