Make Excel Column Name

Post your working scripts, libraries and tools for AHK v1.1 and older
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Make Excel Column Name

17 Jan 2019, 15:37

If this goal is already done in AHK, just tell me. I will delete this post.

I'm with MS Office 2013 32 Bit.
MS Excel column has its own naming system :thumbdown: .
The 1st one is "A"
The 2nd one is "B"
...
..
.
The 16384th, the last, is "XFD"
I wrote a simple function to make it.
Actually, I saw it somewhere in Internet (sorry, I forgot the source link. It is C#)
So, this code it just simple porting.

Code: Select all

Loop, 16384
	myResult .= ExcelColumnNumberToName(A_Index) " "						
FileAppend, % myResult, myFile.txt
Run, myFile.txt
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ExcelColumnNumberToName(x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{
	If(x < 1) 
		Return
	Return ExcelColumnNumberToName(Floor((x - 1) / 26)) Chr(Mod(x - 1, 26) + Asc("A"))     
}
Have a fun with.. a reverse function. "ExcelColumnNameToNumber" !!!

Regards
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Make Excel Column Name

17 Jan 2019, 15:59

ah...
I just tried not to use COM PIA at all.
Because, I an not going to execute Execl application at all.
Last edited by IMEime on 17 Jan 2019, 16:02, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Make Excel Column Name

17 Jan 2019, 16:02

I wrote some code for converting between Excel column letters and numbers here. Cheers.
combinations and permutations (and anagrams) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 23#p164723
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Make Excel Column Name

17 Jan 2019, 16:08

@jeeswg

Yes, I just visited.
Nice, That's good codes too.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Make Excel Column Name

18 Jan 2019, 17:38

Just followed natural process
Not so elegant (?). But, Working !!

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ExcelColumnNameToNumber(columnName)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{
	nameLength := StrLen(columnName)
	characterValue := Asc(SubStr(columnName, 1, 1)) - Asc("A") + 1
	If (nameLength = 1) 
		Return	characterValue
	powerValue := characterValue * (26 ** (nameLength - 1))		
	Return ExcelColumnNameToNumber(SubStr(columnName, 2)) + (powerValue = 1 ? 0 : powerValue)
}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 156 guests