How can I automatically unbold some of the text in a table?

Dicksonk

New Member
Joined
Dec 8, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi there - I am a real novice at VBA. I have an Excel table with names of books in a cell a long with the author and are entered as such e.g. "To Kill a Mocking Bird" - Harper Lee

I would like to be able to have the dash as well as the text that follows to be normal text "To Kill a Mocking Bird" - Harper Lee. Can this be done?

Thanks
Dickson
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Dicksonk()
   Dim Cl As Range
   Dim x As Long
   
   For Each Cl In Range("F2", Range("F" & Rows.Count).End(xlUp))
      x = InStr(1, Cl.Value, "-", 1)
      If x > 0 Then Cl.Characters(x, Len(Cl.Value)).Font.Bold = False
   Next Cl
End Sub
Change the range to suit.
 
Upvote 0
Thanks I have tried it, but I am so new to this that it only changed one cell. I guess I have a lot to learn. Does the C1 in the above code refer cell c1? and in the second line "Dim C1 as Range" if my data is sitting in column F (row 5-150) would I change that all the C1 to F? Also, I tried to change it, but I am getting and Invalid Next control variable reference.

Sub Dicksonktest()
Dim C1 As Range
Dim x As Long

For Each C1 In Range("F5:F100", Range("F" & Rows.Count).End(xlUp))
x = InStr(1, Cl.Value, "-", 1)
If x > 0 Then Cl.Characters(x, Len(Cl.Value)).Font.Bold = False
Next Cl

End Sub

Thanks for your assistance.
 
Upvote 0
Rather than retyping the code, it is best to just copy/paste it. That way won't make any typos. ;)
The C1 should be Cl (lower case L)
 
Upvote 0
Thank you - I worked out why it didn't work. It is because I had concatenated cells within the range.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,533
Messages
6,120,076
Members
448,943
Latest member
sharmarick

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