问题
Referring from my previous question.
VBA code to add current date in next cell
How do I select the previous ten days data from current date entry. Example :As per my first screenshot Lets say i get the today entry will be on Column E and I want to select previous 10 entries to create a graph. So, if I come tomo, my entry will be on F and I want to select column F,E,D,C,,,,
回答1:
Keeping you previous code from link, try this (untested):
edited after OPs clarifications
Option Explicit
Sub Update()
Dim nCols As Long, nOffset As Long
With Range("A1").CurrentRegion
With .Offset(, .Columns.Count - 1).Resize(1, 1)
If .value < Date Then nOffset = 1
With .Offset(, nOffset)
.Resize(2, 1).value = Application.Transpose(Array(Date, Application.WorksheetFunction.Subtotal(103, Worksheets("Stock").UsedRange.Columns(1).SpecialCells(XlCellType.xlCellTypeVisible))))
nCols = IIf(.Column > 10, 10, 10 - .Column - 1)
.Offset(, -nCols + 1).Resize(, nCols).Select
End With
End With
End With
End Sub
来源:https://stackoverflow.com/questions/39426748/vba-code-to-auto-select-previous-10-columns