开发者

Error 1004 method range of object failed?

I'm almost done with a project that updates existing sheets of data. But开发者_如何学Python 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜