Q
查找指定的範圍
0
A
回答
0
使用結束(xlToRight)。
+1
這是錯誤的做法:)想象一下,如果Activecell位於最後一列? – 2013-04-30 21:30:30
+0
優秀點...我總是忘記'查找'。感謝您將此引起我的注意。 – Marshall 2013-04-30 21:44:13
1
第一
第一件事不要使用UsedRange
來設置範圍。我已經解釋過HERE,爲什麼你不應該使用UsedRange
Set RngSource = ActiveWorkbook.ActiveSheet.UsedRange
查找最後一列有數據和最後一行其中有數據,然後設置你的範圍。所以你不會出現從範圍中找到最後一列的問題。下面是一個例子
Sub Sample()
Dim ws As Worksheet
Dim rng As Range
Dim lRow As Long, lCol As Long
'~~> Set your worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
'~~> Find Last Row
lRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
'~~> Find Last Column
lCol = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
Else
lRow = 1: lCol = 1
End If
'~~> Set your range
Set rng = .Range(.Cells(1, 1), .Cells(lRow, lCol))
Debug.Print rng.Address
End With
End Sub
相關問題
- 1. 查找範圍
- 2. 查找日期範圍與指定日期範圍相交的行
- 3. C#檢查指定範圍內的丟失範圍
- 4. 查找指定段的webm視頻的字節範圍
- 5. 查找定義的一組範圍之外的所有範圍
- 6. Excel查找範圍內指定值的最後一條記錄
- 7. 的SQLQuery來查找日期在指定範圍內
- 8. 查找指定日期範圍內的最大值
- 9. NSAttributedString指定範圍?
- 10. 與給定的時間範圍相交查找時間範圍
- 11. SQL查找範圍
- 12. 查找給定範圍內的數字?
- 13. Rails ActiveRecord在指定範圍內通過標記查找問題
- 14. 如何查找NSDate是否在指定範圍內?
- 15. 查找C中的範圍
- 16. 查找範圍內的值
- 17. 變量的查找範圍
- 18. 查找特定時間範圍
- 19. 縱向查找在特定範圍
- 20. VBA查找 - 查找範圍錯誤
- 21. 使用barplot指定範圍
- 22. 沒有指定範圍 - Google_Auth_Exception
- 23. 角指令範圍:設定
- 24. 只讀指定範圍
- 25. 指定索引範圍
- 26. 指定日期範圍
- 27. 在範圍中查找列
- 28. 查找ASCII字符範圍
- 29. 查找範圍SQL複製
- 30. 查找屬性範圍
'RngSource.Columns(RngSource.Columns.Count).Column' – NickSlash 2013-04-30 21:26:14
見[此](http://www.siddharthrout.com/2012/11/09/find-last- excel-sheet-vbavb-net /) – 2013-04-30 21:28:19