+ Reply to Thread
Results 1 to 13 of 13

Hide cell contents using VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    06-17-2015
    Location
    Philadelphia, USA
    MS-Off Ver
    2010
    Posts
    11

    Hide cell contents using VBA

    Hi experts,


    I am trying to write a vba code to hide contents of few cells in the worksheet.

    I have the cell address that needs the modification in another cell.

    The code should take the cell number and hide the contents of the text that is being displayed in another cell.

    For example:

    C2=D98

    D98= Marketing

    I would like to see the Marketing text to be hidden/white text.

    Regards,
    Wunder

  2. #2
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Hide cell contents using VBA

    Try this:
    ActiveSheet.Range("D98").Font.Color = vbWhite
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  3. #3
    Registered User
    Join Date
    06-17-2015
    Location
    Philadelphia, USA
    MS-Off Ver
    2010
    Posts
    11

    Re: Hide cell contents using VBA

    Quote Originally Posted by nigelbloomy View Post
    Try this:
    ActiveSheet.Range("D98").Font.Color = vbWhite
    Hmm

    Thanks Nigel.

    But it has to reference the cell C2 in the sheet first. d98 is not static and keeps changing depending on the user.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,884

    Re: Hide cell contents using VBA

    Maybe:
    Sub FormatFont()
        Range(Cells(2, 3).Value).Font.ColorIndex = 2
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  5. #5
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Hide cell contents using VBA

    Sorry. I didn't understand the first time. This should work then.

    Sub test()
    stValue = Range("C2").Formula
    stValue = Right(stValue, Len(stValue) - 1)
    ActiveSheet.Range(stValue).Font.Color = vbWhite
    End Sub

  6. #6
    Registered User
    Join Date
    06-17-2015
    Location
    Philadelphia, USA
    MS-Off Ver
    2010
    Posts
    11

    Re: Hide cell contents using VBA

    Quote Originally Posted by nigelbloomy View Post
    Sorry. I didn't understand the first time. This should work then.

    Sub test()
    stValue = Range("C2").Formula
    stValue = Right(stValue, Len(stValue) - 1)
    ActiveSheet.Range(stValue).Font.Color = vbWhite
    End Sub
    Hi Nigel,

    Thanks again.

    I get a run time error '1004'

    When I use the above code.

    It points to
    ActiveSheet.Range(stValue).Font.Color = vbWhite
    Does range take stValue?

  7. #7
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Hide cell contents using VBA

    It will if stValue is a string. Try this:

    Dim stValue As String
    stValue = Range("C2").Formula
    stValue = Right(stValue, Len(stValue) - 1)
    ActiveSheet.Range(stValue).Font.Color = vbWhite

  8. #8
    Registered User
    Join Date
    06-17-2015
    Location
    Philadelphia, USA
    MS-Off Ver
    2010
    Posts
    11

    Re: Hide cell contents using VBA

    Hmm changed it and it still shows the error.

  9. #9
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Hide cell contents using VBA

    It works for the example you posted. What is the actual formula in C2? This code can only handle a formula like =D98. The code looks at the formula in C2 and takes off the = sign and then gives that to the range to turn white. If the formula has more in it like =if(D98="Marketing,"Marketing,""), then we need to use a different method to find the cell reference in there.

  10. #10
    Registered User
    Join Date
    06-17-2015
    Location
    Philadelphia, USA
    MS-Off Ver
    2010
    Posts
    11

    Re: Hide cell contents using VBA

    Quote Originally Posted by nigelbloomy View Post
    It works for the example you posted. What is the actual formula in C2? This code can only handle a formula like =D98. The code looks at the formula in C2 and takes off the = sign and then gives that to the range to turn white. If the formula has more in it like =if(D98="Marketing,"Marketing,""), then we need to use a different method to find the cell reference in there.
    Hi Nigel,

    Thanks.

    The cell C2 just has D98 and not =D98.

    The cell C2 tells the code to modify the cell that needs to be hidden.

  11. #11
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Hide cell contents using VBA

    If it doesn't have the = sign then you should be able to use something simpler like this:
    Dim stValue As String
    stValue = Range("C2").Value
    ActiveSheet.Range(stValue).Font.Color = vbWhite

  12. #12
    Registered User
    Join Date
    06-17-2015
    Location
    Philadelphia, USA
    MS-Off Ver
    2010
    Posts
    11

    Re: Hide cell contents using VBA

    Thanks.

    Works a treat.

  13. #13
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Hide cell contents using VBA

    I am glad we finally figured it out.

+ 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. Hide cell contents
    By Kuehl5000 in forum Excel General
    Replies: 1
    Last Post: 04-17-2013, 12:32 PM
  2. [SOLVED] Hide cell contents
    By oceanside in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-13-2013, 08:53 PM
  3. Hide cell contents
    By oceanside in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-13-2013, 08:07 PM
  4. hide cell contents without column or row hide
    By ravergirl7216 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2010, 11:20 AM
  5. I want to hide cell contents
    By Diane Kloecker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2007, 04:22 PM

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