+ Reply to Thread
Results 1 to 9 of 9

Vba code to hide formulas

  1. #1
    Registered User
    Join Date
    12-12-2017
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    4

    Vba code to hide formulas

    Hello everyone,

    I want to hide formulas in formula bar by using macro code without protecting sheets/excel. User only can see the result that driven by the formula. Could anyone advice/provide me how to do this?

    Thanks in advance..

    Kalai

  2. #2
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Vba code to hide formulas

    not possible; however, you could change the cell(s) format to value
    If your original question was resolved, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.
    Click on the Add Reputation button (located at the lower-left corner of all post) for those who assisted you in solving your issue.

  3. #3
    Registered User
    Join Date
    12-12-2017
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    4

    Re: Vba code to hide formulas

    Hi Syrkrasi,

    Thanks, ok. is there any vba code to protect and hide formulas in the formula bar?

    Kalai

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Vba code to hide formulas

    Not Strictly True.

    You can use a macro that runs whenever you select a cell.

    The macro would copy the formula into a string.

    The macro would then copy paste values into the cell.

    When another cell is selected the macro is run again.

    The macro re-enters the formula into the cell.

    Right Click on your sheet name at the bottom of excel and select view code.

    Paste this code in to the module that opens and then close it.

    Please Login or Register  to view this content.


    I suppose you could amend it a bit.


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 12-12-2017 at 05:10 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  5. #5
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Vba code to hide formulas

    Quote Originally Posted by mehmetcik View Post
    Not Strictly True.

    You can use a macro that runs whenever you select a cell...
    .
    It is easy to Lock and hide the cell that contains formulas; however, you will still need to protect the sheet in order to initiate its settings. Hence, this is what the OP is trying to avoid doing.

  6. #6
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Vba code to hide formulas

    I received an error when I clicked into the sheet

    Run-time error '1004':
    Method 'Range' of object '_Worksheet' failed

    error shows this line: Range(Add1).Formula = Formulal

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Vba code to hide formulas

    The Macro is in the sheet named Test.

    You cannot open the macro in that sheet with the test code.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 12-12-2017 at 05:11 PM.

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Vba code to hide formulas

    Quote Originally Posted by mehmetcik View Post
    The Macro is in the sheet named Test.

    You cannot open the macro in that sheet with the test code.
    He stated he received the error when he clicked in the sheet.

    If the test sheet is the active sheet when the workbook is opened and you trigger the selection change event you are going to get the error because Add1 is an empty string.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  9. #9
    Registered User
    Join Date
    12-19-2019
    Location
    USA
    MS-Off Ver
    MS OFFICE 365
    Posts
    1

    Re: Vba code to hide formulas

    ALL WRONG!

    MAKE YOUR FORMULA CUSTOM FUNCTION IN EXCEL.

    FOR THE BASIC EXAMPLE BELOW THE USER WILL ONLY SEE "PERIM_SQFT(THKNESS, ITEM, QTY, LNFT)"

    THE FORMULA WORKS IN VBA BACKGROUND.

    THEN LOCK DOWN VBA WITH A PASSWORD.

    --------------------------------------------------------------------------------------------

    Function PERIM_SQFT(THKNESS, ITEM, QTY, LNFT)

    Dim D_AISC_CHART As Range
    Set D_AISC_CHART = Worksheets("ITEMS DATABASE").Range("B4:AE4000")

    If THKNESS > 0 Then
    SQFT = LNFT * 2 * QTY
    Else: SQFT = QTY * LNFT * Application.WorksheetFunction.VLookup(ITEM, D_AISC_CHART, 3, 0)
    End If

    If QTY = 0 Then
    PERIM_SQFT = 0
    Else: PERIM_SQFT = SQFT
    End If

    End Function
    Attached Images Attached Images
    Last edited by PStateline; 12-19-2019 at 12:24 PM.

+ 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. [SOLVED] How to hide formulas
    By mittmje in forum Excel General
    Replies: 2
    Last Post: 11-27-2016, 05:03 PM
  2. [SOLVED] Which below code, I can Hide & unhide, but I want only allow to HIDE
    By rajeshn_in in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-14-2016, 04:10 AM
  3. [SOLVED] I have HIDE & PROTECT code, But i want ONLY HIDE, can any one edit this !!!
    By rajeshn_in in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2016, 02:03 AM
  4. [SOLVED] Need Formulas to Hide Partial Concatenate Data and Help Determining Two Other Formulas
    By Mattdim805 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-13-2013, 04:11 PM
  5. 'Hide rows with formulas but no data' - Sheet Event Code problem
    By OLLY-7 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-03-2013, 04:02 AM
  6. Code to hide columns based on date criteria and insert another column with formulas
    By RandiLee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2012, 11:04 AM
  7. code to add formulas to a range with previous formulas appearing inside the new one
    By Excel-o-ratoR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2010, 06:02 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