Results 1 to 10 of 10

change number format based on another cell?

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-16-2009
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel XP, 2003, 2010
    Posts
    125

    change number format based on another cell?

    Hi Everyone,

    I'm new to this and also VBA so please show me some 'nab patience'
    I have used this forum periodically and it has saved my bacon on numerous occasions so I know someone can help with this!

    I created a workbook for staff planning and it's becoming a behemoth!

    I'm wanting a range of cells within a row to change the number format to "[hh]:mm" based on a value in the 2nd column of that row.
    I have played about with a few things and can't seem to get it to work. What I have so far is this:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim myCell As Range
    If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
    For Each myCell In Intersect(Target, Range("B:B"))
    If UCase(myCell.Value) = "P/T" Then
    Cells(myCell.Row, 3).NumberFormat = "[hh]:mm"
    End If
    If UCase(myCell.Value) = "F/T" Then
    Cells(myCell.Row, 3).NumberFormat = general
    End If
    Next myCell
    End Sub
    Sample data:

    A B C D E
    Staff member 1 F/T 27 3 24
    Staff member 2 F/T 20 3 17
    Staff member 3 P/T 176:00 3 4.333333333
    Satff member 4 P/T 170:00 3 4.083333333
    Staff member 5 F/T 20 3 17

    Column C has an 'IF' nested with 'vlookup' to reference from another sheet based on column B value

    Column D has the total leave taken so far in the year

    Column E is 'C' minus 'D' = leave remaining.

    So, I want D and E to have the same number format as C.

    I can't do this manually as this sheet auto updates the staff data as new staff join and staff leaving which would mean these manually formatted cells would be out of sync as rows are auto inserted/deleted.

    I have tried to be as precise as I can but if I missed anything out, please ask.

    Thanks in advance!
    Last edited by Fidd$; 09-18-2009 at 09:55 AM. Reason: update info

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1