How to Underline part of text in a cell

sheltton

New Member
Joined
Apr 2, 2008
Messages
21
I've been doing alot of research for the past week on this topic and came up with top two answers .
1. you cant do it
2. you can do it but only if it is broken up.
3. find another option.

lets say i want to do this.

and have been trying really hard to find en number of ways.

code 1 by pgc01
----------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim s1 As String, s2 As String

' only if D1 changes
If Target.Address <> "$D$1" Then Exit Sub

' write the text in A1
s1 = " The Agreement between (The ""Company"") and "
s2 = " (The ""Customer"")"
Range("A1") = s1 & Range("D1") & s2

' add underline to the format of the words "Company" and "Customer"
Range("A1").Characters(InStr(1, Range("A1"), "Company", vbTextCompare), Len("Company")).Font.Underline = True
Range("A1").Characters(InStr(1, Range("A1"), "Customer", vbTextCompare), Len("Customer")).Font.Underline = True

End Sub
----------------------

(i have been hopping)
code 2 from itags.org
----------------------
Function CopyNumberWithOneUnderlinedCharacter(ByVal myCell As Range)
Dim l_Position As Integer
For l_Position = 1 To Len(myCell.Value)
If myCell.Characters(Start:=l_Position, Length:=1).Font.Underline _
<> xlUnderlineStyleNone Then

CopyNumberWithOneUnderlinedCharacter.Characters(St art:=l_Position,
Length:=1).Font.Underline = xlUnderlineStyleSingle
End If
Next l_Position
End Function
----------------------
therse were the best two answers i could find out for underlineing a part of a sentence in a cell.

now my question here is for some one who can put up a function for a sell only or formatting.

for example
A1 = The
B1 = Cow
C1 = jumped
D1 = over
E1 = the
F1 = moon.

lets say my data is like this. if i really want to join the sentense all i have to do is "=A1&B1&C1&D1&E1&F1" (without quots)

can someone come up with a function to underline just 1 cell

hypothetically C1

thus bringing me to a formula
"=A1&B1&underline(C1)&D1&E1&F1" (without quots)

ideally this should be the case isnt it ?

Any suggestions on how to go about this.... i've just theorized the theory.

Some one help me put this in motion.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You can manipulate individual character properties easy enough. The problem is finding, or keeping track of, the characters you want to manipulate. The "Characters" property wants you to specify the starting character and how many characters following. If it is a dynamic string it will definetly require some finess in calculating character positions.

The sample below is about as simple as it gets. I hope it helps.

Gary

Code:
Public Sub Test()
 
'Put a value in cell "A1"
ActiveSheet.Range("A1").Value = "This is a test"
 
'Turn on underlining starting at the 6th character and continue
'underlining for 4 characters (6th character included) underline "is a"
ActiveSheet.Range("A1").Characters(6, 4).Font.Underline = True
 
End Sub
 
Upvote 0
can someone come up with a function to underline just 1 cell

hypothetically C1

thus bringing me to a formula
"=A1&B1&underline(C1)&D1&E1&F1" (without quots)

ideally this should be the case isnt it ?

Simple answer: NO, you cannot do it. You cannot have text resulting from a fomula with characters with different formats.

All the characters of a text resulting from a formula always have the same format.

You can only have more than one format in the characters of a cell if the cell has a constant value, not a formula. In that case yes, you can change the format of just some characters in the text.

To change the format of some characters in the constant text of a cell you have my example in your post #1 and in Gary's example. If you need the text to reflect changes in other cells you have to do it in vba.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top