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
Bookmarks