Show
khoavu87Vũ Trần KhoaTham gia5/3/09Bài viết1,311Được thích1,766Nghề nghiệp Kỹ Sư Xây dựng cầu đường
câu lệnh này có nghĩa là : Tham gia22/6/09Bài viết75Được thích7
Bác hướng dẫn thêm về End đi, em thấy có 2 loại:
và End( điền số:1,2,3,4)
Tham gia19/12/10Bài viết2,571 Được thích5,679Nghề nghiệp Công nhân vệ sinh số liệu Return to VBA Code Examples This tutorial will show you how to use the Range.End property in VBA. Most things that you do manually in an Excel workbook or worksheet can be automated in VBA code. If you have a range of non-blank cells in Excel, and you press Ctrl+Down Arrow, your cursor will move to the last non-blank cell in the column you are in.
Similarly, if you press Ctrl+Up Arrow, your cursor will move to the first non-blank cell. The same applies for a row using the Ctrl+Right Arrow or Ctrl+Left Arrow to go to the beginning or end of that row. All of these key combinations can be used within your VBA code using the End Function. Range End Property SyntaxThe Range.End Property allows you to move to a specific cell within the Current Region that you are working with. expression.End (Direction) the expression is the cell address (Range) of the cell where you wish to start from eg: Range(“A1”) END is the property of the Range object being controlled. Direction is the Excel constant that you are able to use. There are 4 choices available – xlDown, xlToLeft, xlToRight and xlUp. Moving to the Last CellThe procedure below will move you to the last cell in the Current Region of cells that you are in.
Counting RowsThe following procedure allows you to use the xlDown constant with the Range End property to count how many rows are in your current region.
While the one below will count the columns in the range using the xlToRight constant.
Creating a Range ArrayThe procedure below allows us to start at the first cell in a range of cells, and then use the End(xlDown) property to find the last cell in the range of cells. We can then ReDim our array with the total rows in the Range, thereby allowing us to loop through the range of cells.
When we run this procedure, it will return the following message box. VBA Coding Made EasyStop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! Learn More! |