错误1004 对象的方法范围失败?

发布于 2024-11-27 03:38:02 字数 716 浏览 1 评论 0原文

我几乎完成了一个更新现有数据表的项目。但只有一个错误使我无法选择要从新文件导入的数据范围

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2024-12-04 03:38:02

您可以尝试:

Range("A1:" & LastCell).Select

如果您想从 A1 到 LastCell 进行选择。如果没有引号,A1 只是该代码片段中我的“本地”窗口的一个变体。

You might try:

Range("A1:" & LastCell).Select

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文