473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to get excel col. letter

This is my first attempt working with Excel from vb.net. Whew!

I'm trying to get the column letter so that I can create a range variable.

1. I am looping thru the sheets using :
for i = 1 to objExcel.Sheets.Count()

2. Then I want to loop thru the columns using:
for iCol = 1 to objExcel.activesheet.columns.count()

This is where I need the range variable so that I can issue something like:

objExcel.Range(cRange).Select()
Does anyone understand this? I'm probably not being clear enough,
but if you do understand this, can you help?

My project is to loop thru all cells in a workbook to find links to servers.
We are
migrating from Novell to MSFT and our server names are going change and I
need
to update our corp.'s spreadsheets.
Thanks Mucho!
Marc Miller
May 10 '06 #1
2 6728
Marc Miller wrote:
This is my first attempt working with Excel from vb.net. Whew!

I'm trying to get the column letter so that I can create a range variable.

1. I am looping thru the sheets using :
for i = 1 to objExcel.Sheets.Count()

2. Then I want to loop thru the columns using:
for iCol = 1 to objExcel.activesheet.columns.count()

This is where I need the range variable so that I can issue something like:

objExcel.Range(cRange).Select()

Excel column and row references are numeric. If you need the letter,
you'll have to do the conversion. But for a range you'll want the
column number anyway.

T
May 10 '06 #2
Hello Marc,

As tomb suggests, you may not actually need the column "letter". There
are other ways to get the ranges you need. If you really do want the
letter, you can get it thus:

Dim TopCellAddr As String = xlSheet.Cells(1, iCol).Address
Dim ColumnLetter As String
ColumnLetter = TopCellAddr.Substring(1, TopCellAddr.Length - 3)

where xlSheet is the Worksheet that you are working with (e.g.
"objExcel.activesheet")

But you probably don't want to iterate through ALL columns (and rows).
It could take a long time to scan a lot of empty cells. Consider
iterating through the cells (or columns/rows) in xlSheet.UsedRange instead.

Also, unless you're actually interacting with a user, it is usually not
necessary (or even desirable) to activate/select the workbooks, sheets
and cells that you are working with. Just work with the objects
directly (assigning them to a variable of the appropriate type where
this is beneficial).

Cheers,
Randy
Marc Miller wrote:
This is my first attempt working with Excel from vb.net. Whew!

I'm trying to get the column letter so that I can create a range variable.

1. I am looping thru the sheets using :
for i = 1 to objExcel.Sheets.Count()

2. Then I want to loop thru the columns using:
for iCol = 1 to objExcel.activesheet.columns.count()

This is where I need the range variable so that I can issue something like:

objExcel.Range(cRange).Select()
Does anyone understand this? I'm probably not being clear enough,
but if you do understand this, can you help?

My project is to loop thru all cells in a workbook to find links to servers.
We are
migrating from Novell to MSFT and our server names are going change and I
need
to update our corp.'s spreadsheets.
Thanks Mucho!
Marc Miller

May 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: J medina | last post by:
I have an ASP Script that imports an Excel Page to a HTML page. The problem I have that it displays all cells that have only numbers in it but not for numbers that precedes a letter (i.e. 12345...
1
by: peteyjr | last post by:
Hi I have a asp page with a database connection where I need to export adresses into a MS Word Serial Letter. Is this possible and if how?? Any help is well appreciated Peter
2
by: Fred | last post by:
Hi. How do I import while mapping an excel table to an access table please??? I've searched around and all I can find is a software product or code that does the same thing as the access...
1
by: John Hewitt | last post by:
A 'newbie' question - importing into Access from Excel. Googled the group postings but I can't find the amswer I have a 50 line three column file in Excel that contains Names and Tel numbers....
2
by: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get...
6
by: Brent | last post by:
Having used every combonation of excel 9/10/11 and office 10/11 possible as references i still can not create an excel object! Any ideas? Just using this simple bit below i get "Excel.appication...
5
by: bruxerjk | last post by:
I need to do the following. I want to copy cells from a number of Excel files, say "1.xls", "2.xls", "3.xls", etc, into successive rows of "All.xls". That is, I'd open "1.xls", copy cells and...
0
NeoPa
by: NeoPa | last post by:
VlookUp or Vertical LookUp is a function that enables Excel to ‘Find’ related items from within a range stored elsewhere. Elsewhere can mean another excel workbook on another PC, but can also mean a...
2
by: Melissa Mill | last post by:
Hi, I am hoping someone can help me with an error I am getting with my VBA code in Excel 2003. Error is "The object invoked has disconnected from its clients". I have an excel spreadsheet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.