LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default excel script question -- numbers to words

In a generous mood today, so here goes:

Paste the following code in the worksheet code module for the sheet yo
will be entering the numbers. (Right click on sheet tab and select vie
code to get there.)

Code
-------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count = 1 Then 'Only one cell changed
If Target.Row = 1 And Target.Column = 1 And Target.Column <= 10 Then 'A1 through A10
Application.EnableEvents = False 'Disable events
Target.Value = Application.WorksheetFunction.VLookup(Target.Value , Sheets("Sheet2").Range("A1:B4"), 2)
Application.EnableEvents = True 'Reenable events
End If
End If

End Su
-------------------

This is an event procedure which will run whenever a cell is changed o
this worksheet. I'll take you through it.
1. Check to see if only one cell was changed (count=1)
2. Check to see if in the range A1-A10. You can change this b
changing the .Row and .Column values to fit into your desired range.
3. Disable events. Since we are changing a cell here, we don't wan
this event to run again.
4. Target.Value is the changed cell's value. Apply the VLooku
function on it using a table on another sheet. I'll explain this a bi
more later.
5. Turn event handling back on so it will work next time too.

The way VLOOKUP works in your case:

=VLOOKUP(LookupValue, LookupTable, ReturnColumn)

The lookup value is the number you entered.
The lookup table is a set of two columns with the numbers in one an
the return values (words/phrases) in the next. The table shoud b
sorted by number.
The return column in your case would be 2 (the column with th
words/phrases).

To change my code to handle your case, you will first need to creat
your lookup table on another sheet. Then replace Sheets("Sheet2") wit
whatever your sheet name is where the lookup table resides. Replac
Range("A1:B4") with the range of your lookup table.

Post back with questions,



--
Message posted from http://www.ExcelForum.com



 
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
How do I convert numbers to words in Excel Mike of Book Worm Angels Excel Worksheet Functions 1 June 8th 07 09:13 PM
question about some excel restriction script running on ... roise_r Excel Discussion (Misc queries) 0 March 30th 06 11:53 AM
question about some excel restriction script running on ... roise_r Excel Discussion (Misc queries) 0 March 30th 06 11:44 AM
Can you display numbers as words in excel (eg. 10 as ten)? Stefan White Excel Discussion (Misc queries) 2 October 5th 05 04:38 PM
How can I change Numbers in WOrds in Excel A J Excel Discussion (Misc queries) 3 May 9th 05 08:14 AM


All times are GMT +1. The time now is 07:47 PM.

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"