Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
b o b
 
Posts: n/a
Default Formatting a cell based on another cells value

hello-

I would like to format a cell number type based on another cells value.
For instances I have two columns A and B. Column A is a list of
numbers and column B is a list of units. Depending on what type of
unit is enter in column B, I would like excel to adjust the type of
number in column A. The example below shows a two decimal place number
for units of Amps and a fraction for units of HP. I do not what to
have to manually format column A to accomodate for different types of
units.

ex: A B
10.25 Amps
1/3 HP

  #2   Report Post  
Posted to microsoft.public.excel.misc
Ken Johnson
 
Posts: n/a
Default Formatting a cell based on another cells value

b o b wrote:
hello-

I would like to format a cell number type based on another cells value.
For instances I have two columns A and B. Column A is a list of
numbers and column B is a list of units. Depending on what type of
unit is enter in column B, I would like excel to adjust the type of
number in column A. The example below shows a two decimal place number
for units of Amps and a fraction for units of HP. I do not what to
have to manually format column A to accomodate for different types of
units.

ex: A B
10.25 Amps
1/3 HP


Hi b o b,

I think you have to use a Worksheet_Change Event Procedure, like the
following which will set the format of a column A cell when the unit is
entered into the column B cell in the same row...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Columns(2)) Is Nothing Then
Select Case Target.Value
Case "HP"
Cells(Target.Row, 1).NumberFormat = "# ?/?"
Case "Amps"
Cells(Target.Row, 1).NumberFormat = "0.00"
Case Else
Cells(Target.Row, 1).NumberFormat = "General"
End Select
End If
End Sub

To get the code in place...

1. Copy it here
2. Go back to your worksheet and right click its tab.
3. Select "View Code" from the popup menu
4. Paste the code into the sheets code module
5. Press Alt + F11 to get back to the worksheet
6. Save

Ken Johnson

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
Cell Formatting Conditional On Other Cells Fill Color? [email protected] Excel Worksheet Functions 1 April 5th 06 10:05 PM
Conditional coloring of Excel cells, based on adjacent cell values? Greg Stuart Excel Worksheet Functions 0 March 10th 06 10:14 PM
Transfer Cell Formatting for linked cells Scott Excel Discussion (Misc queries) 2 November 23rd 05 11:04 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


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