Solved

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

Posted on 2006-07-06
4
3,131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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 is an explanation of a simple data model to help parse a JSON feed
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

728 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