Results 1 to 7 of 7

Conditionally change number format based on another cell's value

Threaded View

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

    Unhappy Conditionally change number format based on another cell's value

    Hi Everyone,

    I have tried to get this sorted by a few methods but nothing seems to work.
    What I want the formatting to do is this:

    Format the number in Column AL to '[hh]:mm' when Column C's value is ="P/T", otherwise format to 'General'

    Column C's value is referenced from another sheet in the same workbook via a VLOOKUP function.

    Column AL's value is based on an IF formula which goes like this:
    =IF($C4="F/T",SUM($AJ4)+($AK4/2),SUM($D4:$AH4))

    Basically the above formula asks if Column C's value is F/T then count (because if F/T then the corresponding values in that row are whole numbers). If not, then SUM (because if P/T the corresponding values in that row are set to [hh]:mm format).

    I have another sheet in the same workbook which has code (quoted below) which does something similar but I don't understand it enough to get it doing what I want for the sheet in question.

    Private Sub Worksheet_Change(ByVal target As Range)
    Dim myCell As Range, ws As Worksheet, vMatch As Variant, strFormat As String
    On Error Resume Next
    If Intersect(target, Range("B:B")) Is Nothing Then Exit Sub
    For Each myCell In Intersect(target, Range("B:B"))
        strFormat = IIf(UCase(target.Value) = "P/T", "[hh]:mm", "General")
        myCell.Offset(, 3).Resize(, 4).NumberFormat = strFormat
        For Each ws In ActiveWorkbook.Worksheets
            If IsDate("01 " & ws.Name) Then
                With ws
                    vMatch = Application.Match(target.Offset(, -1).Value, ws.Columns(2), 0)
                    If IsNumeric(vMatch) Then ws.Cells(vMatch, "AL").NumberFormat = strFormat
                End With
            End If
        Next ws
    Next myCell
    End Sub
    I know the above may sound quite confusing (it does to me!!) so if further explanations and/or example sheet is needed then please ask.

    Many thanks,
    Tony
    Last edited by Fidd$; 12-07-2009 at 08:19 AM.

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