+ Reply to Thread
Results 1 to 5 of 5

VBA If function

  1. #1
    Registered User
    Join Date
    09-28-2016
    Location
    Bath, England
    MS-Off Ver
    2016
    Posts
    7

    VBA If function

    Hi All,

    I am trying to use a VBA function to hide unused worksheets. The code is as follows:

    Private Sub worksheet_change(ByVal target As Excel.Range)
    Select Case Worksheets("Door Data Entry").Range("r26").Value
    Case "Yes"
    Worksheets("LH Door Inking Detail").Visible = True
    Worksheets("RH Door Inking Detail").Visible = True
    Case "No"
    Worksheets("LH Door Inking Detail").Visible = False
    Worksheets("RH Door Inking Detail").Visible = False
    End Select
    End Sub

    However, in order for this to work, the cell 'r26' cannot seem to have its contents created by a function in the cell. It only works if I type a value of 'Yes' or 'No' directly into the cell.

    I'd like to use a vba function that changes the value of this cell based on that of another cell, e.g.

    If cell 'q15' in 'Door Frame' = "No Lock" then worksheets("Door Data Entry").range("r26") = No

    Else worksheets("Door Data Entry").range("r26") = Yes

    Sorry if I haven't explained very well. Let me know if I need to clarify.

    Thanks,

    Richard

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,422

    Re: VBA If function

    Does't matter. The routine will fire for ANY change on the worksheet.

    Please Login or Register  to view this content.
    Last edited by TMS; 10-26-2016 at 12:34 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-28-2016
    Location
    Bath, England
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA If function

    Ah, ok, it's working after something else is changed in the workbook.

    Thanks for your reply!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,422

    Re: VBA If function

    Note that the amended routine is looking at lower case values

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,422

    Re: VBA If function

    You might have switched off Event handling.

    Thanks for the rep.

+ 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] Usage of standard functions into custom function (or user defined function)
    By tusharb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2016, 12:43 AM
  2. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  3. VBA code for custom function that returns detail results of array function
    By onechipshot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2015, 06:30 PM
  4. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  5. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  6. Replies: 2
    Last Post: 03-20-2009, 01:29 PM
  7. Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04:05 PM

Tags for this Thread

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