+ Reply to Thread
Results 1 to 7 of 7

When clicking cell within range, make it bold. If already bold, make it not bold

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-23-2015
    Location
    Yada, Wales
    MS-Off Ver
    Office 2013
    Posts
    176

    When clicking cell within range, make it bold. If already bold, make it not bold

    I want to add a macro to a button so when a cell is selected within range E10:F20 and I click the macro button, the cell content becomes bold.
    But if content already is bold, make content not bold

    How do I achieve this?
    Last edited by jokris; 06-08-2016 at 12:56 PM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: When clicking cell within range, make it bold. If already bold, make it not bold

    Hi there,

    Try entering the following code in the VBA CodeModule of the worksheet for which you wish to provide this feature, and see if it does what you need:


    
    
    Option Explicit
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        Const sTARGET_RANGE As String = "E10:F20"
    
        Dim iNoOfCells      As Integer
    
        On Error Resume Next
            iNoOfCells = Target.Cells.Count
        On Error GoTo 0
    
        If iNoOfCells = 1 Then
    
            If Not Intersect(Target, _
                             Me.Range(sTARGET_RANGE)) Is Nothing Then
    
                Target.Font.Bold = Not Target.Font.Bold
    
            End If
    
        End If
    
    End Sub
    The highlighted value may be altered to suit your own requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: When clicking cell within range, make it bold. If already bold, make it not bold

    In the sheet module:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim rInt As Range
    
      Set rInt = Intersect(Target, Range("E10:F20"))
      If Not rInt Is Nothing Then rInt.Font.Bold = Not rInt(1).Font.Bold
    End Sub
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    11-23-2015
    Location
    Yada, Wales
    MS-Off Ver
    Office 2013
    Posts
    176

    Re: When clicking cell within range, make it bold. If already bold, make it not bold

    It works good, thank you.

    But how do I do if I want a macro button that (when clicked) switches selected cell between bold and blue vs not bold not blue within same range E10:F20?

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: When clicking cell within range, make it bold. If already bold, make it not bold

    Hi again,

    See if the following code does what you need:

    
    
    Public Sub ToggleCell()
    
        Const sTARGET_RANGE As String = "E10:F20"
        Const lDARK_BLUE    As Long = &HFF0000
        Const lBLACK        As Long = 0
    
        Dim rCell           As Range
    
        For Each rCell In Selection.Cells
    
            With rCell
    
                If Not Intersect(rCell, _
                                 ActiveSheet.Range(sTARGET_RANGE)) Is Nothing Then
    
                    If .Font.Bold = True Then
    
                          .Font.Bold = False
                          .Font.Color = lBLACK
    
                    Else: .Font.Bold = True
                          .Font.Color = lDARK_BLUE
    
                    End If
    
                End If
    
            End With
            
        Next rCell
    
    End Sub
    Select one or more cells and then run the macro to toggle the appearance of the cells.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  6. #6
    Forum Contributor
    Join Date
    11-23-2015
    Location
    Yada, Wales
    MS-Off Ver
    Office 2013
    Posts
    176

    Re: When clicking cell within range, make it bold. If already bold, make it not bold

    Greg, it's perfect!
    Thank you!

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: When clicking cell within range, make it bold. If already bold, make it not bold

    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated

    You're welcome - glad I was able to help.

    Best regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. If a name in one range exists in another, then make that name bold....
    By rcicconetti in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-17-2016, 07:32 PM
  2. [SOLVED] How to make one cell bold & color ????
    By BRout in forum Excel General
    Replies: 9
    Last Post: 01-13-2016, 07:55 AM
  3. Separating Bold from After-Bold Parts of Cell Strings
    By mlexcelhelpforum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2012, 07:11 AM
  4. How to make some text in a Cell Bold?
    By v2jtb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2012, 11:00 AM
  5. How to make cell value bold along with other data
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2010, 08:54 AM
  6. Conditional Format-make bold the lowest value in a range
    By uplink600 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-21-2007, 07:47 AM
  7. [SOLVED] How do you make some characters in a cell bold and some not?
    By tracman in forum Excel General
    Replies: 4
    Last Post: 03-28-2005, 01:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1