Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can you implement a custom format with VB code?

What I want to do is have numbers entered in cells that represen
lengths in milimeters. I want to have a custom format that displays th
numbers in either milimeters or inches depending on an external switch

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Can you implement a custom format with VB code?

Hi
not possible with custom formats in this case

-----Original Message-----
What I want to do is have numbers entered in cells that

represent
lengths in milimeters. I want to have a custom format

that displays the
numbers in either milimeters or inches depending on an

external switch.


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

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Can you implement a custom format with VB code?

What's your external switch?

In this eg I've assumed you change a cell named "units"
and a defined range named "mmIn" of one or more cells for
your custom formats:

in the Worksheet module

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Not Intersect(Target, Range("units")) Is Nothing Then
If Range("units") = "mm" Then
Range("mmIn").NumberFormat = "_-""mm""* #,##0"
Else
Range("mmIn").NumberFormat = "_-""inch""* #,##0.00"
End If
End If

End Sub

Regards,
Sandy
-----Original Message-----
What I want to do is have numbers entered in cells that

represent
lengths in milimeters. I want to have a custom format

that displays the
numbers in either milimeters or inches depending on an

external switch.


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

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Can you implement a custom format with VB code?

You can certainly do this using VBA, though not as a format.

One way:

Select all the cells you want to convert and name them, say
"convert_cells". Assume the "external switch" is a validated cell (named
say, "switch") that contains either "mm" or "in":

Public Sub ToggleConversion()
Dim rArea As Range
Dim rCell As Range
Dim dFactor As Double
dFactor = 25.4 ^ (-1 - 2 * (Range("switch").Value = "mm"))
For Each rArea In Range("convert_cells").Areas
For Each rCell In rArea
rCell.Value = rCell.Value * dFactor
Next rCell
Next rArea
End Sub




In article ,
pH7 wrote:

What I want to do is have numbers entered in cells that represent
lengths in milimeters. I want to have a custom format that displays the
numbers in either milimeters or inches depending on an external switch.

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
custom number format code using letters and numbers Foo Foo Daddy Excel Worksheet Functions 15 December 26th 16 12:33 PM
Need help with converting CUSTOM format/TEXT format to DATE format Deo Cleto Excel Worksheet Functions 6 June 2nd 09 08:14 PM
Format Cell as custom type but data doesn't display like I custom. ToMMie Excel Discussion (Misc queries) 6 September 11th 08 08:31 AM
how to implement xbrl mariano Excel Discussion (Misc queries) 0 January 18th 06 02:00 PM
How would I implement this cell increment? Kia Excel Discussion (Misc queries) 3 January 4th 06 12:11 AM


All times are GMT +1. The time now is 04:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"