?
Solved

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

Posted on 2006-07-06
4
Medium Priority
?
3,133 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Six Sigma Control Plans
Starting up a Project

770 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