Solved

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

Posted on 2006-07-06
4
3,116 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual xHarbour 1 74
java constructor error 8 86
creating threads in delphi 1 53
Not needed 13 53
This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now