Hello Guys,
I got the following sheet with a worksheet change event code. The code is supposed to show $174.34 in bold and red and the rest of text in A2 as normal black fonts. But is showing a portion of the other text in bold and red. Can you please tell me what is wrong with my code?
I got the following sheet with a worksheet change event code. The code is supposed to show $174.34 in bold and red and the rest of text in A2 as normal black fonts. But is showing a portion of the other text in bold and red. Can you please tell me what is wrong with my code?
Excel Workbook | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
2 | In this cost, Driver costs, Running & Maintenance, and Overheads costs are Avoidable Costs. These come to $ 174.34. | ||||||
3 | In this cost, Driver costs, Running & Maintenance, and Overheads costs are Avoidable Costs. These come to $ 174.34. | ||||||
4 | $ 174.34 | ||||||
5 | |||||||
6 | |||||||
7 | |||||||
8 | |||||||
9 | Working Notes and explanations for getting the figures | ||||||
10 | |||||||
11 | Unit Measures | # of Units | Unit Cost | Total Cost | |||
12 | |||||||
13 | Driver Costs | Casual Driver min Hrs | 3:00 | $ 49.78 | $ 149.34 | ||
14 | Running and Maintenance | Contract Kilometres | 30 | $ 0.62 | $ 18.66 | ||
15 | Overheads | Buses x Hours | 1:20 | $ 4.75 | $ 6.33 | ||
16 | Capital Cost | Buses x Hours | 1:20 | $ 23.96 | $ 31.95 | ||
17 | |||||||
18 | Total | $ 206.28 | |||||
Sheet |
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim objISect As Range
Set objISect = Intersect(Target, Range("C13:D16"))
If Not objISect Is Nothing Then
Range("A2").Value = Range("A3").Text
Range("A2").Font.Bold = False
Range("A2").Font.ColorIndex = 0
Range("A2").Characters(InStr(1, Range("A2").Text, Range("A4").Text), _
Len(Range("A4").Text)).Font.Bold = True
Range("A2").Characters(InStr(1, Range("A2").Text, Range("A4").Text), _
Len(Range("A4").Text)).Font.ColorIndex = 3
End If
End Sub