LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Art
 
Posts: n/a
Default Format a cell with a custom number format

Armor,

This may not be the sort of thing you're looking for, but I think it works.
Hopefully there's a simpler solution that someone else can offer -- but I
don't know what it might be.

You've got to write a macro, or actually just paste this one into your
worksheet.

First the macro:
--------------------------------------------------
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Static Skip As Boolean
If Not Skip Then
'If Skip is true, the routine will not run.
'This is used to prevent the routine from causing
'itself to run.
Skip = False

'Check for valid conditions
If Target.Rows.Count 1 Then Exit Sub
If Target.Columns.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
If Target.Row 5 Or Target.Row < 2 Then Exit Sub
If Target.Column < 2 Then Exit Sub
If Not IsNumeric(Target) Then Exit Sub

If Target < Round(Target, 1) Then
MsgBox ("You have too many digits after the decimal")
Exit Sub
End If

'Do the actual conversion
Skip = True
If Target <= 9.9 And Target 0 Then
Target = CStr(Target) & "GHz"
ElseIf Target = 100 And Target <= 999 Then
Target = CStr(Target) & "MHz"
Else
'A final invalid condition with regard to the range.
MsgBox (Target & " is an invalid value")
End If
End If
Skip = False
End Sub
--------------------------------------------------

Now, what do you do with it.

Open the Visual Basic Editor -- either through Tools, Macros or by hitting
Alt-F11.

When you do that you should see a whole bunch of stuff. On the left you'll
see a tree of workbooks, worksheets and some other stuff. Find your workbook
and worksheet.

Double Click your sheet and you should see a blank panel in the center.
Paste the macro there.

The macro will respond to any changes in values on that particular sheet
only. I've put some stuff in there so that you can isolate a range of cells
that should be affected. In my example you can enter you values only in rows
2-5 and column B.

Good luck. I won't be offended if this is not the sort of thing that you
want to use.

Art

"Armor" wrote:

I would like to type in a number and if the number meets a certain criteria,
return that number with a unit identifier.

I.E. a number "A1<= 9.9" returns "value for A1GHz" and if "A1=100, A1<=999"
returns "value for A1MHz"

I would to type a single place, decimal digit under 10 and get that value
with the unit identifier "GHz". By the same token, if the number is greater
100, but less than 999, show the value with the identifier "MHz".

Thank You

 
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
change custom format number to text joey Excel Discussion (Misc queries) 3 September 20th 05 09:35 PM
Linking customer number format to a cell Bobak Excel Discussion (Misc queries) 2 August 8th 05 08:09 PM
Custom number format always defaults last number to 0. scubadave Excel Discussion (Misc queries) 2 June 15th 05 10:20 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
Format Cell (Number Custom) barryderay Excel Discussion (Misc queries) 1 April 28th 05 12:18 AM


All times are GMT +1. The time now is 07:54 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"