Q: D1=(A1&B1)...I want the result of B1 Bold when result show i.e. Biplab (A1) & Rs.12/-(B2). In Cell No. C1 there is formula =(A1&" "B1)...Now Result I want "Biplab Rs.12/-"..... Only Rs.12/- is BOLD. (Note: Length of B1 is not fixed)
Let's create a function called Bold which will make any character under the function to bold. and you can use it directly in the sheet using formula feature.
here is the two thing.
Put the Following function in the Module
Function BOLD(ByRef Text As String) As String
Text = "!" & Text
BOLD = Text
End Function
Now Goto the Sheet and choose we will work on Worksheet_Change Event
here is the Code.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim I As Variant
I = Target.Value
Dim A As String
Dim B As String
Dim ALEN As Integer
Dim BLEN As Integer
Dim TargetColumnNo As Integer
TargetColumnNo = 3
If Target.Column = TargetColumnNo Then
If VBA.InStr(1, I, "!") > 0 Then
A = VBA.Left(I, Application.WorksheetFunction.Find("!", I, 1) - 1)
B = VBA.Mid(I, VBA.InStr(1, I, "!") + 1, VBA.Len(I) - VBA.InStr(1, I, "!"))
ALEN = VBA.Len(A)
BLEN = VBA.Len(B)
Target.Value = A & " " & B
Target.Characters(ALEN + 2, BLEN).Font.FontStyle = "Bold"
Else
Exit Sub
End If
End If
End Sub
Now Suppose in the Sheet1 and Column 3 would be your target column then
write the following formula and you will get the required result.
=A1&BOLD(B1)
Thank you.
No comments:
Post a Comment