我正在尝试将公式从一个单元格拖动到右侧的另一个单元格(即cellA1 [formula: A2 + A3] -> cellB1 [formula: B2+B3])
。这是我的操作):
Dim lastColumn As Long
lastColumn = Workbook2.Worksheets(7).Cells(1, Columns.Count).End(xlToLeft).Column
cellSource = Workbook2.Worksheets(7).Cells(3, lastColumn)
cellTarget = Workbook2.Worksheets(7).Cells(3, lastColumn + 1)
cellSource.AutoFill Destination:=cellTarget, Type:=xlFillDefault
错误是“需要对象”
最佳答案
试试下面的代码:
Dim lastColumn As Long, cellSource As Range, cellTarget As Range
lastColumn = Workbook2.Worksheets(7).Cells(1, Columns.Count).End(xlToLeft).Column
Set cellSource = Workbook2.Worksheets(7).Range(Cells(3, lastColumn).Address)
Set cellTarget = Workbook2.Worksheets(7).Range(Cells(3, lastColumn), Cells(3, lastColumn + 1))
cellSource.AutoFill Destination:=cellTarget, Type:=xlFillDefault
关于excel - VBA从左到右拖动公式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16300573/