Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default LastColumn used as letter(s) in VBA

I have the following code to determine the last column used which returns a
numeric. Is there a method to translate this alpha using VBA e.g. 33 = "AG"

LastColumn =
ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRang e.Columns.Count).Column

Thanks for any assistance,
Kevin


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default LastColumn used as letter(s) in VBA

I just got this to work:

lastcolumn = Mid(ActiveSheet.UsedRange.Columns.Address, 7, 1)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default LastColumn used as letter(s) in VBA

Hi,

I would be careful about using the UsedRange method, for this one can be
fooled by any fomatting that has been previously done by the user.
For instance, if you enter a value in a cell just below the end of your
data table and wipe it out later, the UsedRange method will return the
number of the row (as the last one) where you previously entered the
data whereas there's nothing anymore.

So long

GALLAGHE a écrit :
I have the following code to determine the last column used which returns a
numeric. Is there a method to translate this alpha using VBA e.g. 33 = "AG"

LastColumn =
ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRang e.Columns.Count).Column

Thanks for any assistance,
Kevin


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default LastColumn used as letter(s) in VBA

Hi,

You don´t need to convert, use something like:
var = ActiveSheet.UsedRange.Address _ReferenceStyle:=xlA1)

and then with the text functions (mid, left, etc) you can extract form
var the column letter you need.

Rg
Mika

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default LastColumn used as letter(s) in VBA

I improved upon this because it doesnt account for the last column
being AG (as opposed to Z). So here you go:

lastcolumnname = ActiveSheet.UsedRange.Columns.Address
startofcolumnname = WorksheetFunction.Search(":", lastcolumnname, 4) +
2
endofcolumname = WorksheetFunction.Search("$", lastcolumnname,
startofcolumnname) - 1
lastcolumn = Mid(lastcolumnname, startofcolumnname, endofcolumname + 1
- startofcolumnname)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default LastColumn used as letter(s) in VBA

Mika,

Excellent! One question, I am using version 2002 and had to change the code
to below lose the "_" preciding ReferenceStyle to run.

var = ActiveSheet.UsedRange.Address(ReferenceStyle:=xlA1 )

Any reason why?

Many thanks,
Kevin



"Mika" wrote in message
oups.com...
Hi,

You don´t need to convert, use something like:
var = ActiveSheet.UsedRange.Address _ReferenceStyle:=xlA1)

and then with the text functions (mid, left, etc) you can extract form
var the column letter you need.

Rg
Mika


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default LastColumn used as letter(s) in VBA

Thanks for the advise, I will take this under consideration. Again thanks
for your time.

"anonymousA" wrote in message
...
Hi,

I would be careful about using the UsedRange method, for this one can be
fooled by any fomatting that has been previously done by the user.
For instance, if you enter a value in a cell just below the end of your
data table and wipe it out later, the UsedRange method will return the
number of the row (as the last one) where you previously entered the
data whereas there's nothing anymore.

So long

GALLAGHE a écrit :
I have the following code to determine the last column used which

returns a
numeric. Is there a method to translate this alpha using VBA e.g. 33 =

"AG"

LastColumn =

ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRang e.Columns.Count).Column

Thanks for any assistance,
Kevin




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default LastColumn used as letter(s) in VBA

Chip,
Many thanks for the assistance and your time!!!
Kevin

"Chip" wrote in message
oups.com...
I improved upon this because it doesnt account for the last column
being AG (as opposed to Z). So here you go:

lastcolumnname = ActiveSheet.UsedRange.Columns.Address
startofcolumnname = WorksheetFunction.Search(":", lastcolumnname, 4) +
2
endofcolumname = WorksheetFunction.Search("$", lastcolumnname,
startofcolumnname) - 1
lastcolumn = Mid(lastcolumnname, startofcolumnname, endofcolumname + 1
- startofcolumnname)



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default LastColumn used as letter(s) in VBA

Mika meant it to be one statement continued on a second line:

var = ActiveSheet.UsedRange.Address( _
ReferenceStyle:=xlA1)

would work as well.

Also, I have never seen a need to convert a column number to a letter - are
you sure you need to.
--
Regards,
Tom Ogilvy

" wrote in
message ...
Mika,

Excellent! One question, I am using version 2002 and had to change the

code
to below lose the "_" preciding ReferenceStyle to run.

var = ActiveSheet.UsedRange.Address(ReferenceStyle:=xlA1 )

Any reason why?

Many thanks,
Kevin



"Mika" wrote in message
oups.com...
Hi,

You don´t need to convert, use something like:
var = ActiveSheet.UsedRange.Address _ReferenceStyle:=xlA1)

and then with the text functions (mid, left, etc) you can extract form
var the column letter you need.

Rg
Mika




  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default LastColumn used as letter(s) in VBA

I should have realized the "_" but don't typically break code on more then
one line beings all developers have 21" dual monitors. Concerning the need
to convert the numeric to a letter, not something I ever needed before but
it's for working with a type library in another programming language.


"Tom Ogilvy" wrote in message
...
Mika meant it to be one statement continued on a second line:

var = ActiveSheet.UsedRange.Address( _
ReferenceStyle:=xlA1)

would work as well.

Also, I have never seen a need to convert a column number to a letter -

are
you sure you need to.
--
Regards,
Tom Ogilvy

" wrote in
message ...
Mika,

Excellent! One question, I am using version 2002 and had to change the

code
to below lose the "_" preciding ReferenceStyle to run.

var = ActiveSheet.UsedRange.Address(ReferenceStyle:=xlA1 )

Any reason why?

Many thanks,
Kevin



"Mika" wrote in message
oups.com...
Hi,

You don´t need to convert, use something like:
var = ActiveSheet.UsedRange.Address _ReferenceStyle:=xlA1)

and then with the text functions (mid, left, etc) you can extract form
var the column letter you need.

Rg
Mika








  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default LastColumn used as letter(s) in VBA


I'm not a frequent excell/VBA user, but can't you just do this with on
hit with a couple of splits?:

Split(Split(ActiveSheet.UsedRange.Columns.Address, ":")(1), "$")(1

--
JBU
-----------------------------------------------------------------------
JBUK's Profile: http://www.excelforum.com/member.php...fo&userid=3385
View this thread: http://www.excelforum.com/showthread.php?threadid=34657

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default LastColumn used as letter(s) in VBA

Are you talking last column for a particular row.

or are all your rows of equal length.

Or are they of unequal length and you need to find the last actual column
that contains a value.

The suggestion was made to use UsedRange, but the purpose of UsedRange is to
reveal the extent of the cells for which Excel is storing detailed
information and has nothing to do whether the cells actually contain data or
not (although it will at least include those).

Perhaps a clarification of what you want will reveal a good answer.

--
Regards,
Tom Ogilvy


"unknown" wrote:


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a number to a letter of the alphabet to get a letter [email protected] Excel Worksheet Functions 5 May 21st 07 04:25 PM
New Validation option to format 1st letter as Capital letter Jeff Excel Discussion (Misc queries) 5 July 13th 06 05:11 AM
column header changed from letter to number, how return to letter Ron Excel Discussion (Misc queries) 2 May 9th 05 08:34 PM
press letter and go 2 entry begin w letter in data validation drop MCP Excel Programming 1 August 28th 04 05:07 PM
Here's a simple routine for LastRow, LastColumn chris Excel Programming 7 May 25th 04 12:19 AM


All times are GMT +1. The time now is 08:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"