gpt4 book ai didi

vba - VBA 中的参数数量错误或属性分配无效

转载 作者:行者123 更新时间:2023-12-04 21:37:45 24 4
gpt4 key购买 nike

我收到错误消息

Wrong number of arguments or invalid property assignment



在这一行:
Set hello = Range("O" & row, "Q" & row, "W" & row)

但是,宏在 Set hello = Range("O" & row) 下运行平稳。 .所以这意味着这个宏可以选择一个单元格,但是选择多个单元格时会出错。我无法弄清楚我的宏中的哪个设置导致了这个错误。感谢你的帮助。
Sub ImportDatafromotherworksheet()
Dim wkbCrntWorkBook As Workbook
Dim wkbSourceBook As Workbook
Dim rngSourceRange As Range
Dim rngDestination As Range
Dim row As Integer
Dim hello As Range
Set wkbCrntWorkBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set wkbSourceBook = ActiveWorkbook
Set rngSourceRange = Application.InputBox(Prompt:="Select source row", Title:="Source Range", Default:="press Ctrl for multiple selection", Type:=8)
row = rngSourceRange.row
Set hello = Range("O" & row, "Q" & row, "W" & row)

wkbCrntWorkBook.Activate
Set rngDestination = Application.InputBox(Prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
hello.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
wkbSourceBook.Close False
End If
End With
End Sub

最佳答案

你试图结束的应该是(例如)Range("O5,Q5,W5")

Set hello = Range("O" & row & ",Q" & row & ",W" & row)

整个事情是一根弦,而不是三根。

关于vba - VBA 中的参数数量错误或属性分配无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30296949/

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