+ Reply to Thread
Results 1 to 18 of 18

I need to be able to click on a cell to bold/unbold the number in the cell

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    I need to be able to click on a cell to bold/unbold the number in the cell

    I have a monthly vehicle report that I am revamping and I need to build some features into it to increase user friendlieness. I need to be able to click on a cell that has a day of the month in it, to bold or unbold and count/uncount the number of bold days. For example the days of the month will be in cells B6:I9 and the tally box at J7.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Maybe:

    Bold and Count

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim x As Long
    Dim rcell As Range
    x = 0
    If Not Intersect(Target, Range("B6:I9")) Is Nothing Then
        Target.Font.Bold = True
        For Each rcell In Range("B6:I9")
            If rcell.Font.Bold = True Then x = x + 1
        Next rcell
        Range("J7").Value = x
    End If
    End Sub
    Clear Bold and Count
    Sub giligancow()
    Range("B6:I9").Font.Bold = False
    Range("J7").Value = ""
    End Sub

  3. #3
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Can i make it bold with one click and unbold with one click, as well as add and subtract per click? As it is a double click on a cell then a click off the cell creates the bold and the number count in the tally box. It doesn't unbold with a click or subtract when bold is turned off. Thanks for helping

  4. #4
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    If you already have the tally in J7 working with the bold/unbold count, wouldn't it be more efficient to train the people to use Cntrl+B to bold the cell and Cntrl+Z to reverse that action? That way, they can spend less time moving a mouse and more time on the keyboard, which would be faster as well as teach them something.

    Or they can use the "B" icon on the ribbon. But that reequires moving the mouse.

  5. #5
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    I am just trying to create the product that my bosses want. Maybe a way to click to highlight cells with fill color is a better way to do it. I already have a macro that counts highlighted cells. My boss wants a quick easy way to highlight the cells to show the days a given vehicle is used within the month when the report is printed.

  6. #6
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Try putting this code in the Worksheet Module.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        'If the target cell is clear
        If Target.Interior.ColorIndex = xlNone Then
    
            'Then change the background to the specified color
            Target.Interior.ColorIndex = 4
    
            'But if the target cell is already the specified color
            ElseIf Target.Interior.ColorIndex = 4 Then
    
            'Then clear the background color
            Target.Interior.ColorIndex = xlNone
    
        End If
    End Sub
    I think this may be what you need.

  7. #7
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    The above code works whenever a cell is clicked one time, but also highlights cells as you pass through them using TAB or ENTER. So, it wasn't fool-proof. As you know you need to make it that way for bosses who don't know their way around a computer, vainly attempt to understand the concept of "cut and paste" and that something as incredibly simple as binary still gives them too many options.

    This code works with double clicking a cell.
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        'If the target cell is clear
        If Target.Interior.ColorIndex = xlNone Then
    
            'Then change the background to the specified color
            Target.Interior.ColorIndex = 4
    
            'But if the target cell is already the specified color
            ElseIf Target.Interior.ColorIndex = 4 Then
    
            'Then clear the background color
            Target.Interior.ColorIndex = xlNone
    
        End If
    End Sub
    Last edited by Jim885; 11-19-2013 at 12:21 AM.

  8. #8
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Try this .. I used Jim's Code and modified it to do Bold or unbold on double click and modified John's first code for the count.
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
       
       'If the target cell is not bold
       If Target.Font.Bold = False Then
    
          'Then change the font to bold
          Target.Font.Bold = True
    
          'But if the target cell is already bold
       ElseIf Target.Font.Bold = True Then
    
          'Then change the font to not bold
          Target.Font.Bold = False
    
       End If
    
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim x As Long
    Dim rcell As Range
    If Not Intersect(Target, Range("B6:I9")) Is Nothing Then
    For Each rcell In Range("B6:I9")
            If rcell.Font.Bold = True Then x = x + 1
        Next rcell
        Range("J7").Value = x
    End If
    End Sub
    hope this helps..
    Last edited by moonsaga; 11-19-2013 at 10:28 AM.

  9. #9
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    That is nearly perfect. I need the "double click to bold" to be restricted to the B6:I9 range. I also need to add in auto capitolization for ranges (A28:K42) and (J12:J21). I put in:

    [B]Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range

    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    Application.EnableEvents = False

    Set rng = Union([B1], [A28:K42,J12:J21], [G:G]) 'Upper Case
    If Not Intersect(Target, rng) Is Nothing Then
    Target = UCase(Target)
    End If

    Application.EnableEvents = True
    End Sub
    but I get a compile error: Ambiguous name detected. It works on other worksheets that don't have the code you provided. Thanks again for the help!

  10. #10
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    The compile error is due to the two "Worksheet_Change" events conflicting.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'try this way
    Dim rng As Range
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    Application.EnableEvents = False
    
    Set rng = Union([B1], [A28:K42,J12:J21], [G:G]) 'Upper Case
    If Not Intersect(Target, rng) Is Nothing Then
    Target = UCase(Target)
    End If
    
    Application.EnableEvents = True
    End Sub
    Also use [ CODE ] [ /CODE ] tags around your code. "forum rule"
    Last edited by moonsaga; 11-19-2013 at 02:00 PM.

  11. #11
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    I still need the auto bold or click to bold to be limited to the range B6:I9 and the auto caps isn't working properly. It seems like the click to bold is interfering with the auto caps?
    Last edited by giligancow; 11-19-2013 at 03:30 PM.

  12. #12
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Untested, but try this;
    
      For Each xCell In (Target, Range("A28:K42" & "J12:J21")) 
      If UCase(xCell.Text) <> xCell.Text Then xCell.Value = UCase(xCell.Text)
    Next
    ' Not sure if these two lines would be needed. But if so, then set the reverse action before this part of code runs.
    ' Application.Calculation = xlAutomatic
    ' Application.ScreenUpdating = True
     End Sub

  13. #13
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Jim885, I'm sorry but I'm not sure how to use the code that you provided. Below is what I have so far...
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
       
       'If the target cell is not bold
       If Target.Font.Bold = False Then
    
          'Then change the font to bold
          Target.Font.Bold = True
    
          'But if the target cell is already bold
       ElseIf Target.Font.Bold = True Then
    
          'Then change the font to not bold
          Target.Font.Bold = False
    
       End If
    
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim x As Long
    Dim rcell As Range
    If Not Intersect(Target, Range("B7:I10")) Is Nothing Then
    For Each rcell In Range("B7:I10")
            If rcell.Font.Bold = True Then x = x + 1
        Next rcell
        Range("J7").Value = x
    End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rng As Range
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    Application.EnableEvents = False
    
    Set rng = Union([B1], [A27:K37,J11:J21], [G:G]) 'Upper Case
    If Not Intersect(Target, rng) Is Nothing Then
    Target = UCase(Target)
    End If
    
    Application.EnableEvents = True
    End Sub
    Thanks again for helping out a beginner!

  14. #14
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    I got the bold / Unbold to only work in the B6:I9 range...

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    If Not Intersect(Target, Range("B6:I9")) Is Nothing Then  'added this line
       
       'If the target cell is not bold
       If Target.Font.Bold = False Then
    
          'Then change the font to bold
          Target.Font.Bold = True
    
          'But if the target cell is already bold
       ElseIf Target.Font.Bold = True Then
    
          'Then change the font to not bold
          Target.Font.Bold = False
    
       End If  ' added this line
       End If
    
    End Sub
    Hope this helps

  15. #15
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Thank you so much moonsaga! I had tried something similar but didn't have the second "End If". I still can't get the auto upper case to work. It works flawlessly if I don't have the code for the "double click to bold" in there but as soon as I put it in the auto caps doesn't work. The code I have for that is above.

  16. #16
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    I copied your code to my test workbook and It works for me with the rest of the code.. I don't know why it doesn't work for you..

  17. #17
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Hi,

    this is moonsaga's code with the ucase line added.
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    If Not Intersect(Target, Range("B6:I9")) Is Nothing Then  'added this line
       
       'If the target cell is not bold
       If Target.Font.Bold = False Then
          'Then change the font to bold
          Target.Font.Bold = True
    
            Cells(Target.Row, Target.Column) = UCase(Cells(Target.Row, Target.Column))
          'But if the target cell is already bold
       Else
       
       Target.Font.Bold = False
       Cells(Target.Row, Target.Column) = LCase(Cells(Target.Row, Target.Column))
       End If
    End If
    
    End Sub
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  18. #18
    Registered User
    Join Date
    10-23-2013
    Location
    St George, UT
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: I need to be able to click on a cell to bold/unbold the number in the cell

    Thanks xlbiznes but I need a different range to be auto upper case. I have a workbook with only this code and it works great:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    Application.EnableEvents = False
    
    Set rng = Union([B1], [A28:K42,J12:J22], [G:G]) 'Upper Case
    If Not Intersect(Target, rng) Is Nothing Then
    Target = UCase(Target)
    End If
    
    Application.EnableEvents = True
    End Sub
    I also have a workbook with code to bold/unbold a range of 31 numbers that represent a month. It also counts the number of bold numbers and tallies them in a separate cell. The part of the code that runs the bold and count works great but the auto upper case doesn't work in this workbook and is as follows:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      If Not Intersect(Target, Range("B7:I10")) Is Nothing Then
      
       'If the target cell is not bold
       If Target.Font.Bold = False Then
    
          'Then change the font to bold
          Target.Font.Bold = True
    
          'But if the target cell is already bold
       ElseIf Target.Font.Bold = True Then
    
          'Then change the font to not bold
          Target.Font.Bold = False
       End If
       End If
    
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim x As Long
    Dim rcell As Range
    If Not Intersect(Target, Range("B7:I10")) Is Nothing Then
    For Each rcell In Range("B7:I10")
            If rcell.Font.Bold = True Then x = x + 1
        Next rcell
        Range("J7").Value = x
    End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rng As Range
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    Application.EnableEvents = False
    
    Set rng = Union([B1], [A28:K42,J12:J22], [G:G]) 'Upper Case
    If Not Intersect(Target, rng) Is Nothing Then
    Target = UCase(Target)
    End If
    
    Application.EnableEvents = True
    End Sub
    Again, thanks for the help

+ 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. 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
  2. Replies: 2
    Last Post: 02-06-2008, 07:27 PM
  3. Unbold cell in Column
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2007, 10:23 AM
  4. Join bold and non-bold text in one cell
    By bkincaid in forum Excel General
    Replies: 3
    Last Post: 03-20-2006, 09:10 PM
  5. [SOLVED] clicker that advances one number per click in a cell
    By Biff in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 04:05 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