如何从动态起点填写选择?

问题描述

我有以下代码来选择 A 到 E 列中的数据作为起点将是动态的。

ActiveSheet.Columns("A:E").SpecialCells(xlCellTypeConstants,23).Select

然后如何将这些数据填充到 F 列的长度?

示例电子表格。

enter image description here

选择的起点并不总是从第 2 行开始。

例如,数据可能如下所示。

Example Spreadsheet

解决方法

将“Sheet1”重命名为您的数据所在的工作表名称

Set ws = ThisWorkbook.Worksheets("Sheet1")

LastRowA = ws.Range("B" & Rows.count).End(xlUp).Row 'Finds last used row of column A
LastRowF = ws.Range("F" & Rows.count).End(xlUp).Row 'Finds last used row of column F

'Fills down column by column
ws.Range("A" & LastRowA).AutoFill Destination:=ws.Range("A" & LastRowA & ":A" & LastRowF),Type:=xlFillValues
ws.Range("B" & LastRowA).AutoFill Destination:=ws.Range("B" & LastRowA & ":B" & LastRowF),Type:=xlFillValues
ws.Range("C" & LastRowA).AutoFill Destination:=ws.Range("C" & LastRowA & ":C" & LastRowF),Type:=xlFillValues
ws.Range("D" & LastRowA).AutoFill Destination:=ws.Range("D" & LastRowA & ":D" & LastRowF),Type:=xlFillValues
ws.Range("E" & LastRowA).AutoFill Destination:=ws.Range("E" & LastRowA & ":E" & LastRowF),Type:=xlFillValues