这种方法适用于数据从首行A1开始的情况。通过使用Range对象的CurrentRegion属性,可以获取当前区域的行数。vba Dim rng As Range Dim maxRow As Integer Set rng = Range("A1").CurrentRegion maxRow = rng.Rows.Count方法2:UsedRange法 🌐 这种方法适用于数据起点不确定的情况。通过获取工作表的已使用区域,可以确...
在EXCEL中,对数据进行定位操作,必然要用到数据区域的最大行和最大列,代码如下: columnmax = Range("IV1").End(xlToLeft).Column '取得1行的最大列数 columnmax =cells(i,columns.count).end(xltoletf).column 'i行的最大列数 rowmax = Sheet1.Range("a65536").End(xlUp).Row '取得A列的最大行 注...
假定MaxRow变量的值是100,那么这句的意思就是指单元格 A2:B100 从字面上看MaxRow代表最大的行号,这句就是指不包括第一行(往往是表头)的AB两列有数据的单元格
4、第四度种方法:ActiveSheet.range("A1").CurrentRegion.Rows.Count 5、第五种方法:ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row 6、第六种方法:ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row 7、第七种方法:MaxRow =Application.Evaluate("=MAX((A1:A1048576<>""")*ROW(1:1048576))") 抢...
如果要指定某列的最大行,可以用Range("A" & Rows.Count).End(xlUp).Row“A”是要获取最大行的...
lastRow = Application.WorksheetFunction.Max(lastRow, currCell.Row) lastCol = Application.WorksheetFunction.Max(lastCol, currCell.Column) Set dataRange = Range(Cells(1, 1), Cells(lastRow, lastCol)) Set currRange = Union(currCell.EntireRow, currCell.EntireColumn) Set currRange = In...
max_row = .Range("a:a").Rows.Count last_row = .Range("a" & max_row).End(xlUp).Row For i = 6 To last_row total_money = .Range("e" & i).Value first_quarter = .Range("f" & i).Value second_quarter = .Range("g" & i).Value ...
a = .Range("A100000").End(xlUp).Row b = .Range("AX1").End(1).Column .Cells(a + 2, b - 1) = "末行号是:" & a .Cells(a + 3, b - 1) = "末列号是:" & b End With End Sub 【代码解析】: Line1:WITH语句,提取代码中相同的父级对象(Sheets("范围确认")),作为公共从属关系...
MaxRow%= .Rows.count'获取非空行数maxCol% = .Columns.count'获取非空列数数EndWith'获取使用范围内使用的行数、列数x =UsedRange.Rows.count y=UsedRange.Columns.countend sub
Range函数:Range函数用于设置单元格的范围。可以通过指定单元格的行号和列号,或者使用字母表示的单元格地址来设置范围。例如,Range("A1:B10")表示设置A1到B10范围内的所有单元格。 Cells函数:Cells函数用于设置单元格的范围。可以通过指定单元格的行号和列号来设置范围。例如,Cells(1, 1)表示设置第1行第1列的单元...