VBA code to auto select previous 10 columns
我正在尝试从其他工作表添加可见行的返回值。我试图修改该帖子中给出的代码,我肯定在这里做错了,因为它从上面的代码行输入了覆盖值。
Sub Update()
Dim nCols As Long, nOffset As Long, Srce As Range
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
我尝试添加以下行以获取可见行的返回值
.Offset(, .Columns.Count).Resize(3, 1) = Application.Subtotal(103, Sheets("Sharedstocks").Range("A:A"))
请建议
答案 0 :(得分:0)
可能就是你所追求的:
Option Explicit
Sub Update()
Dim nCols As Long, nOffset As Long, Srce As Range
With Range("A1").CurrentRegion
With .Offset(, .Columns.Count - 1).Resize(1, 1)
If .Value < Date Then nOffset = 1
With .Offset(, nOffset)
.Resize(3, 1).Value = Application.Transpose(Array(Date, _
Application.WorksheetFunction.Subtotal(103, Worksheets("Stock").UsedRange.Columns(1).SpecialCells(XlCellType.xlCellTypeVisible)), _
Application.WorksheetFunction.Subtotal(103, Worksheets("SharedStock").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