Hi All,
I was trying to revise a code by adding bits for conditional formatting - if duration is less then a certain number text is aligned left, else its aligned right. The formatting is done within text boxes - shapes. Please see bits of the code below. Is there anything wrong there? Its not working properly as it always aligns the text to the right, never to the left. Any thoughts?
duration = Round((EndTime - StartTime) * 24 * 60) Set GantShape = Worksheets(destSheet).Shapes.AddShape(msoShapeRectangle, LeftPoints, TopPoints, WidthPoints, HeightPoints) With GantShape .Fill.ForeColor.RGB = PatternType.Color .Line.Weight = 0.25 .Name = "WorkingShape" If inBoxString <> "" Then Select Case equipment Case "A" If duration < 1.5 Then .TextFrame.Characters.Text = inBoxString .TextFrame.Characters.Font.Size = PatternType.Parent.Font.Size .TextFrame.Characters.Font.FontStyle = PatternType.Parent.Font.Size .TextFrame.Characters.Font.Color = PatternType.Parent.Font.Color .TextFrame.VerticalAlignment = xlTop .TextFrame.HorizontalAlignment = xlLeft Else .TextFrame.Characters.Text = inBoxString .TextFrame.Characters.Font.Size = PatternType.Parent.Font.Size .TextFrame.Characters.Font.FontStyle = PatternType.Parent.Font.Size .TextFrame.Characters.Font.Color = PatternType.Parent.Font.Color .TextFrame.VerticalAlignment = xlTop .TextFrame.HorizontalAlignment = xlRight End If Case "B" If duration < 0.5 Then .TextFrame.Characters.Text = inBoxString .TextFrame.Characters.Font.Size = PatternType.Parent.Font.Size .TextFrame.Characters.Font.FontStyle = PatternType.Parent.Font.Size .TextFrame.Characters.Font.Color = PatternType.Parent.Font.Color .TextFrame.VerticalAlignment = xlTop .TextFrame.HorizontalAlignment = xlLeft Else .TextFrame.Characters.Text = inBoxString .TextFrame.Characters.Font.Size = PatternType.Parent.Font.Size .TextFrame.Characters.Font.FontStyle = PatternType.Parent.Font.Size .TextFrame.Characters.Font.Color = PatternType.Parent.Font.Color .TextFrame.VerticalAlignment = xlTop .TextFrame.HorizontalAlignment = xlRight End If Case "C" If duration < 5 Then .TextFrame.Characters.Text = inBoxString .TextFrame.Characters.Font.Size = PatternType.Parent.Font.Size .TextFrame.Characters.Font.FontStyle = PatternType.Parent.Font.Size .TextFrame.Characters.Font.Color = PatternType.Parent.Font.Color .TextFrame.VerticalAlignment = xlTop .TextFrame.HorizontalAlignment = xlLeft Else .TextFrame.Characters.Text = inBoxString .TextFrame.Characters.Font.Size = PatternType.Parent.Font.Size .TextFrame.Characters.Font.FontStyle = PatternType.Parent.Font.Size .TextFrame.Characters.Font.Color = PatternType.Parent.Font.Color .TextFrame.VerticalAlignment = xlTop .TextFrame.HorizontalAlignment = xlRight End If End Select End If End With