英文:
This code is to get the data from inv sheet column N to sheet rep column B Run-Time Error "1004" Method 'Range of object_'worksheet' failed
问题
这段代码用于从“inv”工作表的N列获取数据,然后将其写入到“rep”工作表的B列。
fw2 = Me.ListBox1.ListCount - 1
Inv.Range("B9:N500").ClearContents
Inv.Range("B8:N" & 8 + fw2).Cells.Value = ListBox1.List
With Rep
.Range(.Cells(lastrow, "J"), .Cells(lastrow + fw2 - 1, "S")) = Inv.Range("B9:K" & 8 + fw2).Value 'all products
'这里是我想要修改的部分
运行时错误 "1004"
对象“worksheet”的方法“Range”失败
.Range(.Cells(lastrow, "B")) = Inv.Range("N9:N" & 8 + fw2).Value
End With
英文:
This code is to get the data from inv sheet column N to sheet rep column B
fw2 = Me.ListBox1.ListCount - 1
Inv.Range("B9:N500").ClearContents
Inv.Range("B8:N" & 8 + fw2).Cells.Value = ListBox1.List
with Rep
.Range(.Cells(lastrow, "J"), .Cells(lastrow + fw2 - 1, "S")) = Inv.Range("B9:K" & 8 +
fw2).Value 'all products
'Here is the one I want to modify
Run-Time Error "1004"
Method 'Range of object_'worksheet' failed
.Range(.Cells(lastrow, "B")) = Inv.Range("N9:N" & 8 + fw2).Value
End With
答案1
得分: 0
这个错误是在您的表达式中,左边是一个单元格,但右边的范围包含多个单元格时生成的。
将以下行替换为:
.Range(.Cells(lastrow, "B")) = Inv.Range("N9:N" & 8 + fw2).Value
改为:
.Range(.Cells(lastrow, "B"), .Cells(lastrow + fw2, "B")) = Inv.Range("N9:N" & 8 + fw2).Value
英文:
This error is generated when in your expression the left side is one cell, but the right side's range consists of more than one cell.
Replace the line
.Range(.Cells(lastrow, "B")) = Inv.Range("N9:N" & 8 + fw2).Value
to
.Range(.Cells(lastrow, "B") , .Cells(lastrow + fw2, "B")) = Inv.Range("N9:N" & 8 + fw2).Value
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论