错误1004 对象的方法范围失败?
我几乎完成了一个更新现有数据表的项目。但只有一个错误使我无法选择要从新文件导入的数据范围
ChDir "C:\Users\jiarui.hou.THRUBIT\Desktop"
Dim aFile As String
Dim SheetName As String
aFile = Application.GetOpenFilename(Title:="Select Raw Data File to Import")
If aFile = "False" Then Exit Sub
Workbooks.Open Filename:=aFile
'Returns LAST USED cell
LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastColumn = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
LastCell = Cells(LastRow, LastColumn).Address
Range(A1 & ":" & LastCell).Select 'Error 1004:method'Range' of object '_Global' failed
Selection.Copy
有什么建议吗?
I'm almost done with a project that updates existing sheets of data. But there is just one error that keeps me from selecting the range of data I would like to import from a new file
ChDir "C:\Users\jiarui.hou.THRUBIT\Desktop"
Dim aFile As String
Dim SheetName As String
aFile = Application.GetOpenFilename(Title:="Select Raw Data File to Import")
If aFile = "False" Then Exit Sub
Workbooks.Open Filename:=aFile
'Returns LAST USED cell
LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastColumn = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
LastCell = Cells(LastRow, LastColumn).Address
Range(A1 & ":" & LastCell).Select 'Error 1004:method'Range' of object '_Global' failed
Selection.Copy
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试:
如果您想从 A1 到 LastCell 进行选择。如果没有引号,A1 只是该代码片段中我的“本地”窗口的一个变体。
You might try:
If you are wanting to select from A1 to the LastCell. Without the quotes, A1 is just a variant according to my Locals window, in that snippet of code.