首页 > 解决方案 > 从上一行向下复制公式

问题描述

需要从上一行复制公式以自动填充。

destsht("All PO Raw Data 1-18").Columns("V3:X" & destLR).FillDown


Dim wb As Workbook
Dim sht As Worksheet, destsht As Worksheet
Dim destLR As Long, LastRow As Long


Set wb = ThisWorkbook
Set sht = wb.Sheets("Open PO Raw Data")


Set destwb = Workbooks.Open("C:\Users\rc\Desktop\ALL PO RAW DATA 1-18  to present_copy.xlsx")
Set destsht = destwb.Sheets("All PO Raw Data 1-18")
destLR = destsht.Cells(Rows.Count, "A").End(xlUp).Row + 1
 MsgBox destLR


wb.ActiveSheet.Activate
LastRow = sht.Cells(Rows.Count, "A").End(xlUp).Row
sht.Range("A2:U" & LastRow).SpecialCells(xlCellTypeVisible).Copy destsht.Range("A" & destLR)

destsht("All PO Raw Data 1-18").Columns("V3:X" & destLR).FillDown

公式下降到最后一行。最后一行代码给了我错误。我收到 438 错误消息。对象不支持该属性。我想我可能需要一个偏移量而不是我在 V3 显示的内容。

标签: excelvba

解决方案


在粘贴可见单元格后,我不得不修改我的代码来计算行数。现在它一直向下复制。

将 wb 调暗为工作簿 将 sht 调为工作表,将 destsht 调为工作表 将 destLR 调暗,只要 LastRow

Set wb = ThisWorkbook Set sht = wb.Sheets("打开 PO 原始数据")

Set destwb = Workbooks.Open("C:\Users\rc\Desktop\ALL PO RAW DATA 1-18 to present.xlsx") Set destsht = destwb.Sheets("All PO Raw Data 1-18") destLR = destsht .Cells(Rows.Count, "A").End(xlUp).Row + 1 ' MsgBox destLR

wb.ActiveSheet.Activate LastRow = sht.Cells(Rows.Count, "A").End(xlUp).Row sht.Range("A2:U" & LastRow).SpecialCells(xlCellTypeVisible).Copy destsht.Range(" A" & destLR)

Number_of_Rows = sht.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1 ' MsgBox Number_of_Rows

destLR = destLR + Number_of_Rows 'MsgBox destLR

destsht.Range("V3:X" & destLR).FillDown


推荐阅读