gpt4 book ai didi

VBA从左到右拖动公式

转载 作者:行者123 更新时间:2023-12-03 01:06:51 25 4
gpt4 key购买 nike

我正在尝试将公式从一个单元格拖动到右侧的另一个单元格(即cellA1 [公式:A2 + A3] -> cellB1 [公式: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

关于VBA从左到右拖动公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16300573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com