-1

我正在将一个范围复制到另一个工作簿的下一个空单元格中。以下代码;

Public Sub InvoicedInstallments()

Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Dim fname As String
Dim mt As String, yr As String
mt = MonthBox.Value
yr = YearBox.Value
fname = yr & mt & "DB" & ".xlsx"
Set rng1 = Workbooks("201209TB.xlsx").Worksheets("excel").Range("E348")
Set rng2 = Workbooks("201209TB.xlsx").Worksheets("excel").Range("E295")
Set rng3 = Workbooks(fname).Worksheets("UK monthly dashboard").Cells(1, Columns.Count).End(xlToRight).Select

rng3.Value = (rng1.Value + rng2.Value)
rng3.Value = rng3.Value * -1
rng3.Value = Round(rng3.Value / 1000, 0)

End Sub

有过线

Set rng3 = Workbooks(fname).Worksheets("UK monthly dashboard").Cells(1, Columns.Count).End(xlToRight).Select

变成

Set rng3 = Workbooks(fname).Worksheets("UK monthly dashboard").Range("AA49").End(xlToRight).Offset(0, 1)

现在这会将数据放入下一个空单元格(这是我想要的),但如果您再次运行代码,它不会将信息放入下一个空单元格。

我想这只是一些简单的事情,但我无法发现它

它正在复制到合并的单元格中,我怀疑其中存在很多问题(请参阅下面的评论以确认这一点)

4

1 回答 1

0

我猜,你的问题将在这一行:

rng3.Value = Round(rng3.Value / 1000, 0)

但是这里抛出了错误

Set rng3 = Workbooks(fname).Worksheets("UK monthly dashboard").Cells(1, Columns.Count).End(xlToRight).Select

这是因为select.

Select, 选择,它不会返回一个范围对象。

改用这个

Set rng3 = Workbooks(fname).Worksheets("UK monthly dashboard").Cells(1, Columns.Count).End(xlToRight)

但是,我不确定这是否是您想要的,因为您可能只是说

Set rng3 = Workbooks(fname).Worksheets("UK monthly dashboard").Range("IV1")

因为这就是你得到的——至少,如果你只与.xlsx

于 2012-10-23T11:39:34.347 回答