Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Get Column Letter of Active Cell in VBA

On Saturday, July 31, 2010 10:01:10 PM UTC+5:30, MIG wrote:
For some reason, activecell.column returns a number, where as
range.select requires a string.

So it's not possible to, say, select a range based on returning the
current column, or is it?

Is there a way of either

a) returning the column letter or

b) selecting a range based on column number?

Thanks.


Function coletter(col As Integer) As String
arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
If col 26 Then
remainder = col Mod 26
devisor = (col - remainder) / 26
If remainder 0 Then
coletter = Mid(arr, devisor, 1) & Mid(arr, remainder, 1)
Else
coletter = Mid(arr, devisor - 1, 1) & Mid(arr, 26, 1)
End If
Else
coletter = Mid(arr, col, 1)
End If

End Function
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,514
Default Get Column Letter of Active Cell in VBA

On Saturday, July 31, 2010 10:01:10 PM UTC+5:30, MIG wrote:
For some reason, activecell.column returns a number, where as
range.select requires a string.

So it's not possible to, say, select a range based on returning the
current column, or is it?

Is there a way of either

a) returning the column letter or

b) selecting a range based on column number?

Thanks.


Function coletter(col As Integer) As String
arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
If col 26 Then
remainder = col Mod 26
devisor = (col - remainder) / 26
If remainder 0 Then
coletter = Mid(arr, devisor, 1) & Mid(arr, remainder, 1)
Else
coletter = Mid(arr, devisor - 1, 1) & Mid(arr, 26, 1)
End If
Else
coletter = Mid(arr, col, 1)
End If

End Function


It's a lot simpler than that...

range(columns(5).address)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Get Column Letter of Active Cell in VBA

On Thursday, 17 October 2013 23:23:37 UTC+11, GS wrote:
On Saturday, July 31, 2010 10:01:10 PM UTC+5:30, MIG wrote:


For some reason, activecell.column returns a number, where as


range.select requires a string.




So it's not possible to, say, select a range based on returning the


current column, or is it?




Is there a way of either




a) returning the column letter or




b) selecting a range based on column number?




Thanks.




Function coletter(col As Integer) As String


arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


If col 26 Then


remainder = col Mod 26


devisor = (col - remainder) / 26


If remainder 0 Then


coletter = Mid(arr, devisor, 1) & Mid(arr, remainder, 1)


Else


coletter = Mid(arr, devisor - 1, 1) & Mid(arr, 26, 1)


End If


Else


coletter = Mid(arr, col, 1)


End If




End Function




It's a lot simpler than that...



range(columns(5).address)



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion


Cheers Garry

From your suggestion i came up with this function. Will return only the column letter(s). Not sure if it's perfect but working for me.

Function ColToLetter(colNo As Variant) As String

ColToLetter = Mid(Columns(colNo).Address, 2, (InStr(2, Columns(colNo).Address, ":") - 2))

End Function
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,514
Default Get Column Letter of Active Cell in VBA

Cheers back at ya'!

Try this...

Function GetColLabel$(ColNum&)
Split(Replace(Columns(ColNum).Address,"$",""),":") (0)
End Function

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
Extract Column Letter from Cell Reference in another Cell JKBEXCEL Excel Discussion (Misc queries) 2 December 29th 06 04:27 PM
How to determine the column letter from Cell address Jean Excel Worksheet Functions 6 July 24th 06 03:04 AM
How to replace column letter in refferences with a function using the old column letter? Dmitry Kopnichev Links and Linking in Excel 6 October 13th 05 09:09 AM
How to replace column letter in refferences with a function using the old column letter? Dmitry Kopnichev Excel Worksheet Functions 6 October 13th 05 09:09 AM
column header changed from letter to number, how return to letter Ron Excel Discussion (Misc queries) 2 May 9th 05 08:34 PM


All times are GMT +1. The time now is 12:48 PM.

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

About Us

"It's about Microsoft Excel"