+ Reply to Thread
Results 1 to 5 of 5

Add cell formatting to Clear macro?

Hybrid View

  1. #1
    Registered User
    Join Date
    04-26-2010
    Location
    nebraska
    MS-Off Ver
    Excel 2007
    Posts
    13

    Add cell formatting to Clear macro?

    First, thank everyone so much for all of your helpful tips and everything this site offers.

    I am using the following UDF to clear the contents of a range of cells and would like to add the ability to change the text color of some of the cells back to black. Can this be done?

    "Private Sub CLEAR_Click()

    If MsgBox("Are you sure ?", vbYesNo + vbQuestion) = vbNo Then
    Exit Sub
    Else
    Range("B5,b7,c7,b10:b12,b14:b16,b18:b20,c23,e3:e500,f3:f500,g3:g500,h3:h500,i3:i500,j3:j500,m2:m9,m14,m15,n5,l18:l23,m26,m28:m35,m39:m46,m50:m57,m61:m68,m72:m79,m83:m90,m94:m101,m105:m112,n31,n42,n53,n64,n75,n86,n97,n108").Select
    Selection.ClearContents

    End If

    End Sub"

    I want to change the following ranges back to black text: b10:b12,b14:b16,b18:b20 - c23 - e3:e500,f3:f500,g3:g500,h3:h500,i3:i500,j3:j500.

    Any help would be greatly appreciated.

    Adam

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Add cell formatting to Clear macro?

    Hi dillinger
    Please take a few minutes to read the forum rules, and then add the code tags as required.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    04-26-2010
    Location
    nebraska
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Add cell formatting to Clear macro?

    Sorry! I have never posted a chunk of code before. First, thank everyone so much for all of your helpful tips and everything this site offers.

    I am using the following UDF to clear the contents of a range of cells and would like to add the ability to change the text color of some of the cells back to black. Can this be done?

    Private Sub CLEAR_Click()
    
    If MsgBox("Are you sure ?", vbYesNo + vbQuestion) = vbNo Then
    Exit Sub
    Else
    Range("B5,b7,c7,b10:b12,b14:b16,b18:b20,c23,e3:e500,f3:f500,g3:g500,h3:h500,i3:i500,j3:j500,m2:m9,m1 4,m15,n5,l18:l23,m26,m28:m35,m39:m46,m50:m57,m61:m68,m72:m79,m83:m90,m94:m101,m105:m112,n31,n42,n53, n64,n75,n86,n97,n108").Select
    Selection.ClearContents
    
    End If
    
    End Sub
    I want to change the following ranges back to black text: b10:b12,b14:b16,b18:b20 - c23 - e3:e500,f3:f500,g3:g500,h3:h500,i3:i500,j3:j500.

    Any help would be greatly appreciated.

    Adam

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Add cell formatting to Clear macro?

    Hello Adam,

    Welcome to the Forum!

    This will reset the cells to black font.
    Private Sub CLEAR_Click()
    
      If MsgBox("Are you sure ?", vbYesNo + vbQuestion) = vbNo Then
         Exit Sub
      Else
         Range("B5,b7,c7,b10:b12,b14:b16,b18:b20,c23,e3:e500,f3:f500,g3:g500,h3:h500,i3:i500,j3:j500,m2:m9,m1 4,m15,n5,l18:l23,m26,m28:m35,m39:m46,m50:m57,m61:m68,m72:m79,m83:m90,m94:m101,m105:m112,n31,n42,n53, n64,n75,n86,n97,n108").ClearContents
      End If
    
      Range("b10:b12,b14:b16,b18:b20,c23,e3:e500,f3:f500,g3:g500,h3:h500,i3:i500,j3:j500").Font.ColorIndex = 1
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    04-26-2010
    Location
    nebraska
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Add cell formatting to Clear macro?

    Oh wow. How easy is that?! Thank you very much Leith!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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