Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default counting through the alphabet that is above 702..

Have a question.. I'm currently working on a project that's all about
updating excel documents with a current one through a program. since we're
dealing with spreadsheets that have a huge number of cells (some more than
702 sheets) I have to do everything through the program to make it faster..

I have to name the columns alphabetically just like excel does...
e.g. 1 = A, 702 = ZZ, 27 = AZ, so on and so forth..

now I got up to ZZ with one go.. forgive me if I show my solution in c#...
and if it's not optimized then forgive me as well since I'm still new at it.

string[] alphabet = new string[] { "A", "B", "C", "D", ............ , "Z" };
string[] alphabet2 = new string[] { "Z", "A", "B", "C", "D", ...... , "Y" };
//you'll understand why later...//

int input = 0;
int otherletter = 0;

if (input < 27)
{
output = alphabet[input - 1] //since the index starts at 0//
console.writeline(output);
}
else if (input 26) //AA - ZZ or 27-702
{
otherletter = input / 26 //just get the whole number no
fraction..right letter//
input = input % 26; //modulus for the letter on the right//
output += alphabet2[input];
output += alphabet[otherletter];
console.writeline(output);
}

so for 702 (which is ZZ)
input = 702
input = 702 % 26 (which is zero...that is why Z is at index zero in alphabet2)
otherletter = 702 / 26 = 26.something (which uses the alphabet string array)

that isn't very nice to look at but it gets the job done.. the problem now
is what to do beyod 702? I already have a tentative solution.. which includes
using the number 702... it's almost the same as this solution just add
another "else if" but the problem is when I get to 18954 which is "ZZZ" and
so on and so forth?

does it really mean I have to make another else if everytime a letter is
added as the number goes higher? or is there a better logic other than my
approach? I'm sure there is... anybody out there? I don't care if the answer
isn't in C#... I'll just have to get the idea then maybe I could use it..
thanks.. sorry for the poor code work :)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default counting through the alphabet that is above 702..

You can refer to cells by their numerical value thus avoiding the alpha
construct.

e.g Range("ZZ1") = Cells(1,702)

Note: that in the first case the column is first the row second, whilst the
later is Row, then Column


--

Regards,
Nigel




"Jassen Cali" <Jassen
wrote in message
...
Have a question.. I'm currently working on a project that's all about
updating excel documents with a current one through a program. since we're
dealing with spreadsheets that have a huge number of cells (some more than
702 sheets) I have to do everything through the program to make it
faster..

I have to name the columns alphabetically just like excel does...
e.g. 1 = A, 702 = ZZ, 27 = AZ, so on and so forth..

now I got up to ZZ with one go.. forgive me if I show my solution in c#...
and if it's not optimized then forgive me as well since I'm still new at
it.

string[] alphabet = new string[] { "A", "B", "C", "D", ............ ,
"Z" };
string[] alphabet2 = new string[] { "Z", "A", "B", "C", "D", ...... ,
"Y" };
//you'll understand why later...//

int input = 0;
int otherletter = 0;

if (input < 27)
{
output = alphabet[input - 1] //since the index starts at 0//
console.writeline(output);
}
else if (input 26) //AA - ZZ or 27-702
{
otherletter = input / 26 //just get the whole number no
fraction..right letter//
input = input % 26; //modulus for the letter on the right//
output += alphabet2[input];
output += alphabet[otherletter];
console.writeline(output);
}

so for 702 (which is ZZ)
input = 702
input = 702 % 26 (which is zero...that is why Z is at index zero in
alphabet2)
otherletter = 702 / 26 = 26.something (which uses the alphabet string
array)

that isn't very nice to look at but it gets the job done.. the problem now
is what to do beyod 702? I already have a tentative solution.. which
includes
using the number 702... it's almost the same as this solution just add
another "else if" but the problem is when I get to 18954 which is "ZZZ"
and
so on and so forth?

does it really mean I have to make another else if everytime a letter is
added as the number goes higher? or is there a better logic other than my
approach? I'm sure there is... anybody out there? I don't care if the
answer
isn't in C#... I'll just have to get the idea then maybe I could use it..
thanks.. sorry for the poor code work :)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default counting through the alphabet that is above 702..

that's exactly the problem... since our instructor insists on using the alpha
construct.. since the output of the program is an XML based excel document we
need to reconstruct it the way it was and we need to find a logic to generate
the column names in a more optimized way..
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default counting through the alphabet that is above 702..

maybe
cells(1,27).entirecolumn.address
or
left(cells(1,27).entirecolumn.address,instr(cells( 1,27).entirecolumn.address,":")-1)

gives the column name

regards Ernst



"Jassen Cali" schreef in bericht
...
that's exactly the problem... since our instructor insists on using the
alpha
construct.. since the output of the program is an XML based excel document
we
need to reconstruct it the way it was and we need to find a logic to
generate
the column names in a more optimized way..



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 Alphabet yclhk Excel Discussion (Misc queries) 2 December 20th 09 06:41 PM
Why can't I autofill the alphabet? THSaldivar Excel Discussion (Misc queries) 2 July 1st 06 02:08 AM
alphabet to numbers? Loriandme69 Excel Programming 2 November 22nd 05 03:47 AM
"counting" through the alphabet Dr.Schwartz Excel Programming 2 June 27th 05 10:50 AM
Greek alphabet lashio Excel Discussion (Misc queries) 4 June 13th 05 12:41 AM


All times are GMT +1. The time now is 02:50 AM.

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"