PC Review


Reply
Thread Tools Rate Thread

counting through the alphabet that is above 702..

 
 
Jassen Cali
Guest
Posts: n/a
 
      23rd Nov 2007
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

 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      23rd Nov 2007
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
(E-Mail Removed)



"Jassen Cali" <Jassen (E-Mail Removed)> wrote in message
news:BB9B4283-C778-40DB-86BD-(E-Mail Removed)...
> 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
>


 
Reply With Quote
 
Jassen Cali
Guest
Posts: n/a
 
      23rd Nov 2007
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 With Quote
 
Ernst Schuurman
Guest
Posts: n/a
 
      23rd Nov 2007
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" <(E-Mail Removed)> schreef in bericht
news:411CDC2C-5B5A-4936-B2AF-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Next in alphabet accesskastle Microsoft Access Queries 4 21st Dec 2009 11:26 PM
Macro to Click on Alphabet Letter to go to Cell Where that Alphabet Letter Starts in Large Spreadsheet jcp370@comcast.net Microsoft Excel Discussion 2 26th Jul 2005 07:33 AM
"counting" through the alphabet =?Utf-8?B?RHIuU2Nod2FydHo=?= Microsoft Excel Programming 2 27th Jun 2005 10:50 AM
how to add a bar on top of a alphabet ? =?Utf-8?B?TWV0YXJpeWE=?= Microsoft Word Document Management 2 25th Jan 2005 05:59 AM
Using an alphabet other than the Roman alphabet Diane Microsoft Outlook Discussion 0 14th Sep 2003 06:37 PM


Features
 

Advertising
 

Newsgroups
 


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