我差不多完成了一个更新现有数据表的项目。但是只有一个错误使我无法选择我想从新文件中导入的数据范围
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
有什么建议吗?
答案 0 :(得分:3)
您可以尝试:
Range("A1:" & LastCell).Select
如果您想从A1中选择LastCell。如果没有引号,A1只是根据我的Locals窗口的变体,在该代码片段中。