Using VB with Excel 
Author Message
 Using VB with Excel

Hi everyone

I'm doing an import of data from an excel worksheet into an array (to show
in an unbound grid).  My question is, how can I find out the number of
columns that are populated, and the number of populated rows?  IE when a
user presses control-end in Excel the active cell becomes the farthest
bottom right of the populated worksheet.

Your help would be much appreciated,

With many thanks in advance,

Lucy Aldridge



Tue, 12 Feb 2002 03:00:00 GMT  
 Using VB with Excel
You could create a named range within your Excel sheet and then use that
name to access the data from VB.  The excel range object has columns and
rows collections which both have a count property.

Example:

Dim lMaxRows as long

lMaxRows = objExcelSheet.Range("MyRangeName").Rows.Count

This may not be possible if you are accessing the data from ADO.  It would
be possible if you were opening the Excel sheet via automation from VB.

There are pros and cons to both approaches.

Cheers
Rob


Quote:
> Hi everyone

> I'm doing an import of data from an excel worksheet into an array (to show
> in an unbound grid).  My question is, how can I find out the number of
> columns that are populated, and the number of populated rows?  IE when a
> user presses control-end in Excel the active cell becomes the farthest
> bottom right of the populated worksheet.

> Your help would be much appreciated,

> With many thanks in advance,

> Lucy Aldridge



Tue, 12 Feb 2002 03:00:00 GMT  
 Using VB with Excel
 Try this:

    Dim intCol as Integer
    Dim lngRow as Integer

    intCol = Sheet1.UsedRange.Columns.Count
    lngRow = Sheet1.UsedRange.Rows.Count

Peter


Quote:
> Hi everyone

> I'm doing an import of data from an excel worksheet into an array (to show
> in an unbound grid).  My question is, how can I find out the number of
> columns that are populated, and the number of populated rows?  IE when a
> user presses control-end in Excel the active cell becomes the farthest
> bottom right of the populated worksheet.

> Your help would be much appreciated,

> With many thanks in advance,

> Lucy Aldridge



Tue, 12 Feb 2002 03:00:00 GMT  
 Using VB with Excel
try using the UsedRange property of the worksheet


Quote:
> Hi everyone

> I'm doing an import of data from an excel worksheet into an array (to show
> in an unbound grid).  My question is, how can I find out the number of
> columns that are populated, and the number of populated rows?  IE when a
> user presses control-end in Excel the active cell becomes the farthest
> bottom right of the populated worksheet.

> Your help would be much appreciated,

> With many thanks in advance,

> Lucy Aldridge



Wed, 13 Feb 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem using VB in Excel 2000

2. Using VB w/ Excel

3. Making a graph / chart using VB and Excel

4. Importing from Excel to Excel using VB.

5. Excel to VB and VB to Excel

6. VB and Excel problem - VB corrupts Excel environment

7. Compatibility Problem Using MS Excel 97 VBA on Excel 2000/XP - Causes crashes

8. Running VBA code in EXcel from VB6 using EXcel Objects

9. Saving an Excel file without using Excel

10. Saving an Excel file without using Excel

11. Running an excel macro using excel 8 obj lib

12. Using an Excel file without having Microsoft Excel installed

 

 
Powered by phpBB® Forum Software