VBA: Make selection bold when selected

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
I would like it when a cell is selected it will make the text Bold and when you click it again it makes it back to normal ??
 
Try using the revised code I posted in Message #7 as I think it addresses that issue (be sure to read Message #5 to make sure you have all the right code installed). For future consideration... you should read all the messages before using the solution from any one of them so that you can see correction that were posted later on.
Sorry about that I had email to popup and though that was the only post. It is a little different that I was hoping. I was needing the text to stay bold and if you went back and selected it again it would go back to normal. I guess selecting the cell would be like a switch. I didn't explain it that way originally.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Sorry about that I had email to popup and though that was the only post. It is a little different that I was hoping. I was needing the text to stay bold and if you went back and selected it again it would go back to normal. I guess selecting the cell would be like a switch. I didn't explain it that way originally.
You cannot do that with a simple selection... once a cell is selected, "selecting" it again raises no events (Excel does nothing because it is already selected). We can do what you want if you are willing to use a double-click to toggle the bold on and off. Put this, and only this (get rid of the other codes we posted here), in the worksheet's code module...
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Target.Font.Bold = Not Target.Font.Bold
  Cancel = True
End Sub
 
Upvote 0
One possible minor problem with it... select a cell on the managed sheet, then select another sheet, then activate the "Go To" dialog box (ALT+EG) and type a reference back to the managed sheet to a cell different than the one that was selected when you switched sheets... both the previously selected and newly selected cells will both be highlighted.
Good point. I'd think it will extend to workbook open / close cases as well. bamaisgreat, you may think of some other event like Double Click so as to have control over font change.
 
Upvote 0
Good point. I'd think it will extend to workbook open / close cases as well. bamaisgreat, you may think of some other event like Double Click so as to have control over font change.

that is awesome thanks a lot guys.. so lets say I wanted it to change the color of the font and make it bold ??? How would that need to look ?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.Font.Bold = Not Target.Font.Bold
Cancel = True
End Sub
 
Upvote 0
You cannot do that with a simple selection... once a cell is selected, "selecting" it again raises no events (Excel does nothing because it is already selected). We can do what you want if you are willing to use a double-click to toggle the bold on and off. Put this, and only this (get rid of the other codes we posted here), in the worksheet's code module...
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Target.Font.Bold = Not Target.Font.Bold
  Cancel = True
End Sub
Thank you that is awesome .. so lets say I wanted it to change the color of the font to red and make it bold ??? How would that need to look ?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.Font.Bold = Not Target.Font.Bold
Cancel = True
End
 
Upvote 0
Thank you that is awesome .. so lets say I wanted it to change the color of the font to red and make it bold ??? How would that need to look ?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.Font.Bold = Not Target.Font.Bold
Cancel = True
End
Try it like this...
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Cancel = True
  Target.Font.Bold = Not Target.Font.Bold
  Target.Font.ColorIndex = -4102 - Target.Font.ColorIndex
End Sub
The "magic number" -4102 comes from summing up the values -4105 (the value of the built in VB constant xlColorIndexAutomatic - the default color of cells) and 3 (the ColorIndex value for red).
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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