Solved

get the last used column and row excel with vb.net

Posted on 2006-07-06
4
3,130 Views
Last Modified: 2008-01-09
Hello,

I want to know how can I get the last row and column with data in Excel through vb.net. I've developed an application to automate Excel and make
some files and I need to know these values in order to apply correct format.

Thanks in advance.
0
Comment
Question by:nuberun
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
dapcom earned 500 total points
ID: 17050098
something like:

strAddress=Range("A1").SpecialCells(xlLastCell).Address
or
iCol=Range("A1").SpecialCells(xlLastCell).Column
iRow=Range("A1").SpecialCells(xlLastCell).Row

should help?

xlLastCell=11 if you don't have the constants...
0
 
LVL 1

Expert Comment

by:dapcom
ID: 17050130
NB: with automation I guess you need to use a ref to the corrsponding sheet, workbook or applicationto use the Range property. I guess you already have one:

ex:
myExcelApp.WorkBooks(1).Sheets(1).range...

or myWorkbook.Sheets(1).range

mySheet.Range...
0
 

Author Comment

by:nuberun
ID: 17051104
And how can I also get the letter of this column, for example AA.
Thanks
0
 
LVL 1

Expert Comment

by:dapcom
ID: 17056696
I don't know if there's a direct way to do that, I usually profer using the column numbers and change to an address when needed.

Anyway here is a way to get the letter from the address:

Public Sub test()
    Dim strAddress As String
    Dim strColLetter As String
    strAddress = Range("B2").EntireColumn.AddressLocal            'return "$B:$B"
    strColLetter = Mid$(strAddress, 2, InStr(strAddress, ":") - 2)  'get rid of first $ and read until ':'
    MsgBox strColLetter
End Sub

But something tells me an excel function must exist for that?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

730 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