![]() |
Get number of columns and rows
Hi.
I want to read all sheet from excel to my program. As i understand, i can use cell(i,j), but for this i need number of rows and columns, how can i get it? |
Get number of columns and rows
Assuming data starts in A1 and there are no blank rows or columns embedded
Dim v() as Variant set rng = Activesheet.Range("A1").CurrentRegion numrows = rng.rows.count numcols = rng.columns.count redim v(1 to numrows, 1 to numcols) for i = numrows for j = numcols v(i,j) = rng(i,j).value Next Next or for i = numrows for j = numcols val(i,j) = cells(i,j).Value next Next -- Regards, Tom Ogilvy "Artem Omelianchuk" wrote in message ... Hi. I want to read all sheet from excel to my program. As i understand, i can use cell(i,j), but for this i need number of rows and columns, how can i get it? |
Get number of columns and rows
Check the UsedRange property of the Worksheet object. And, you don't
have to go through every cell one at a time. The following transfers the complete worksheet into a 2D matrix in the variant x. Sub testIt() Dim x x = ActiveSheet.UsedRange.Value End Sub -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... Hi. I want to read all sheet from excel to my program. As i understand, i can use cell(i,j), but for this i need number of rows and columns, how can i get it? |
Get number of columns and rows
If you mean the number of used cells on the worksheet:
RowsUsed = Sheets("SheetName").UsedRange.Rows.Count ColumnsUsed = Sheets("SheetName").UsedRange.Columns.Count "Artem Omelianchuk" wrote: Hi. I want to read all sheet from excel to my program. As i understand, i can use cell(i,j), but for this i need number of rows and columns, how can i get it? |
Get number of columns and rows
|
Get number of columns and rows
Dim ws As Worksheet, nColsRows() As Integer, i As Integer i = 0 Const FST_ROW = 0 Const ROW_CNT = 1 Const FST_COL = 2 Const COL_CNT = 3 For Each ws In Worksheets With ws.UsedRange ReDim Preserve nColsRows(3, i) nColsRows(FST_ROW, i) = .Row nColsRows(ROW_CNT, i) = .Row + .Rows.Count - 1 nColsRows(FST_COL, i) = .Column nColsRows(COL_CNT, i) = .Column + .Columns.Count - 1 i = i + 1 End With Nex -- SkipVough ----------------------------------------------------------------------- SkipVought's Profile: http://www.msusenet.com/member.php?userid=198 View this thread: http://www.msusenet.com/t-187051429 |
All times are GMT +1. The time now is 10:33 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com