?
Solved

Excel Automation: how to find the last row numbers in an Excel Sheet?

Posted on 2005-04-30
5
Medium Priority
?
669 Views
Last Modified: 2013-11-20
Hi Experts,

I want to open an Excel file in VC++ and append new data to an existing worksheet. I need to find the last row number in the used range. It seems to be an easy problem, but I keep gettng a count of 25384. What's wrong with this code?

LPDISPATCH lpDisp;
Range range;
lpDisp = sheet.GetUsedRange();
range.AttachDispatch(lpDisp);
range.Select();
range.GetRows();
long lTotalRows = range.GetCount();

Thanks,
Er
0
Comment
Question by:jper_hm
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:NawalKishore1976
ID: 13936047
There is something Called The Special Cells:

Range("A1").Select
    ActiveCell.SpecialCells(xlLastCell).Select


This can be used to go to the last cell    
0
 

Author Comment

by:jper_hm
ID: 13939056
Thanks. How to do this in VC++?  What's the constant value for xlLastCell?
0
 
LVL 3

Accepted Solution

by:
NawalKishore1976 earned 2000 total points
ID: 13943417
Go to excel and go to vba.
Select Object Browser and See the value.

Const xlLastCell = 11
0
 

Author Comment

by:jper_hm
ID: 13946272
Thank you. I still cannot find the equivalent SpecialCells function in excel9.h. Is it this one:

LPDISPATCH Range::SpecialCells(long Type, const VARIANT& Value)




0
 

Author Comment

by:jper_hm
ID: 13949737
Yes, I got it. It's
range.SpecialCells((long)11,covOptional);

Thank you.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question