Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Get number of columns and rows

Thank you.
But i use VC,so i find this:
http://groups.google.ru/group/micros...e=source&hl=ru



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of rows/columns occupied Will Excel Worksheet Functions 4 January 11th 09 10:27 PM
limited columns and rows number Aline New Users to Excel 2 December 20th 07 07:19 PM
Customize number of rows and columns Tuckland Excel Discussion (Misc queries) 3 May 8th 07 11:25 AM
Set number of columns/rows? Paddy Excel Discussion (Misc queries) 4 April 21st 07 06:13 PM
number of columns/rows andrewm Excel Discussion (Misc queries) 1 July 10th 05 12:12 PM


All times are GMT +1. The time now is 02:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"