Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Increment/Increment letter in alphabetical order

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Neil Goldwasser - 25 Jan 2006 00:33 GMT
Does anybody know of some code which would "increase" the letter within a cell?
i.e. if the value of the cell was "A", when you select the cell and run the
macro, it would change the cell value to "B". If you did it again it would
change it to "C", etc... etc...

I have found a way to do it using a helper cell, but I'd much prefer the
macro to operate on just the one cell. My old method was as follows:
A1 starts with the value 65. The formula in B1 = CHAR(A1). (So B1 starts as
"A")
I then selected A1 and used the following macro (assigned to a shortcut to
make it quicker):
Sub Add_1()
   Selection.Value = Selection.Value + 1
End Sub

The reason for requesting this: Sometimes a cell needs to have a particular
letter value to achieve the required output in a resultant cell, but I
wouldn't know straight away what the letter needs to be. Rather than entering
"A", checking the resultant cell, then entering "B", checking again, etc...
(very slow and tedious), I could just keep my finger on the shortcut key
until I see the resultant cell flicker, signalling that I had just passed the
required letter value (much quicker).

Can anybody think of a way (maybe using CODE or CHAR or something?) for this
process to operate without the need for the number format helper cell in A1?

It's really puzzling me, and would make life a lot easier.

Thanks in advance, Neil
Norman Jones - 25 Jan 2006 00:43 GMT
Hi Neil,

Try:

'=============>>
Private Sub CommandButton1_Click()
   Dim rng As Range

   Set rng = Me.Range("A1")

   With rng
       .Value = Chr(Asc(.Value) + 1)
   End With

End Sub
'<<=============

---
Regards,
Norman

> Does anybody know of some code which would "increase" the letter within a
> cell?
[quoted text clipped - 34 lines]
>
> Thanks in advance, Neil
Norman Jones - 25 Jan 2006 00:49 GMT
Hi Neil,

Or, perhaps:

'=============>>
Private Sub CommandButton1_Click()
   Dim rng As Range

   Set rng = Me.Range("A1")

   With rng
       If .Value = "Z" Then
           .Value = "A"
       Else
           .Value = Chr(Asc(.Value) + 1)
       End If
   End With

End Sub
'<<=============

---
Regards,
Norman

> Hi Neil,
>
[quoted text clipped - 57 lines]
>>
>> Thanks in advance, Neil
Neil Goldwasser - 25 Jan 2006 09:07 GMT
You're a star! Absolutely spot on!
Thank you very much - by looking at your code I feel that I am starting to
pick up quite a lot of stuff now!

Cheers again, Neil

> Hi Neil,
>
[quoted text clipped - 82 lines]
> >>
> >> Thanks in advance, Neil
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.