+ Reply to Thread
Results 1 to 12 of 12

Combining Two Functions

  1. #1
    Registered User
    Join Date
    07-28-2015
    Location
    Danville, IL USA
    MS-Off Ver
    2013
    Posts
    34

    Combining Two Functions

    First let me say that I'm a novice at VBA.

    I have a function called ColorCheck3 that looks at the referenced cell below it and returns a text string. I call it out by putting in cell A1 "=ColorCheck3(A2). It works fine until I start filtering (hiding) the rows below it.

    I have another function called NextVis that correctly finds the next visible row below it. I call it out by putting in cell A1 "=NextVis(A2)". As I hide the rows below 1 it properly detects the next visible cell in column A.

    I've been trying in vain to use NextVis to get ColorCheck3 to look at the next visible cell below it. Here's my code:

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer



    Is there a way to get ColorCheck3 to use NextVis as it range? Or am I just going about this in the completely wrong way?

    Thanks in advance for any help.
    Last edited by 6StringJazzer; 07-29-2015 at 11:44 AM. Reason: code tags

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Combining Two Functions

    Try

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 07-29-2015 at 12:24 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    07-28-2015
    Location
    Danville, IL USA
    MS-Off Ver
    2013
    Posts
    34

    Re: Combining Two Functions

    Thank you very much Mr. Deitrick.

    This works perfectly.

  4. #4
    Registered User
    Join Date
    07-28-2015
    Location
    Danville, IL USA
    MS-Off Ver
    2013
    Posts
    34

    Re: Combining Two Functions

    Well,
    Almost perfectly.
    The results are not persistent. If I navigate to another worksheet, when I come back it is displaying the #Value error. Same thing when I close the workbook and reopen it.

  5. #5
    Registered User
    Join Date
    07-28-2015
    Location
    Danville, IL USA
    MS-Off Ver
    2013
    Posts
    34

    Re: Combining Two Functions

    Well,
    Almost perfectly.
    The results are not persistent. If I navigate to another worksheet, when I come back it is displaying the #Value error. Same thing when I close the workbook and reopen it.

    If I go to the cell with the =CheckColor(A1) entry and pretend edit, it comes back. Hitting the Calculate Now button on the formulas ribbon doesn't do anything either.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Combining Two Functions

    Try it with this code:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-28-2015
    Location
    Danville, IL USA
    MS-Off Ver
    2013
    Posts
    34

    Re: Combining Two Functions

    Thanks again for your time Mr. Deitrick.

    Application.Volatile didn't help.

    I do have a Worksheet_Activate() procedure and I've tried various things to call out the function from within it but haven't had any luck. Everything I try complies with errors. Can a function be called out by a procedure?

    Here's my Worksheet_Activate() code (with tags this time). As you can see, it filters the worksheet so only the active row shows and it only triggers if the active row is below row 6 (I had to get help on this one too). I'm trying to use this color check function in row 6 to create dynamic headings based on the background color of the visible active row.


    Please Login or Register  to view this content.


    I also have a Worksheet_Deactivate() procedure. Could something here be causing the problem when I navigate away from the worksheet? This procedure clears the filters and moves the active cell to C1.

    Please Login or Register  to view this content.

    Any suggestions would be appreciated.

    ~ Phil White

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Combining Two Functions

    If you want to have dynamic headers based on the first visible cell of a column, then you really need to explain how the colors are applied - are the colors from CF, or are you filtering already colored cells, or using a macro?

  9. #9
    Registered User
    Join Date
    07-28-2015
    Location
    Danville, IL USA
    MS-Off Ver
    2013
    Posts
    34

    Re: Combining Two Functions

    Mr. Dietrick,

    I am filtering rows based on the active cell. Only the row with the active cell is visible on this worksheet (call it Worksheet 3), which brings it to the top directly under row 6. The active cell that triggers the filtering is being selected by following a hyperlink from a different worksheet (worksheet 2) in the same workbook to a named range in cell A of worksheet 3.

    Colors have already been applied to the cells in all rows below row 6 manually using the Format Cells function (background color fill) and once assigned, do not change. I'm trying to use the CheckColor function in row 6 to assign a heading to the cells in the active row based on their fill color. The active row may extend out as far as column P, it can vary.

    The first cell in the active row that needs a dynamic header is in column C, so I am entering "=CheckColor3(C7)" in cell C6. I then copy that formula to the right so that it becomes "=CheckColor3(D7)", "=CheckColor3(E7)", etc.

    When I initially enter the "=CheckColor()" formula in row 6 and copy it to the right, it returns the correct text string. When I navigate to a different worksheet and then return to worksheet 3 (with the CheckColor headings), either by following the same hyperlink, a different hyperlink to a different row, or by manually selecting the tab for worksheet 3, the result becomes #Value. Closing the workbook and reopening it has the same result regardless of whether I save or not. Neither "Calculate Now" nor F9 will refresh the function to display the correct text string.

    I hope that is enough information to be of use and I again thank you for putting so much of your time into assisting me.

    ~ Phil White

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Combining Two Functions

    Try wrapping your function in a volatile worksheet function, like

    =IF(RAND()<2,CheckColor3(C7),"No calc")

  11. #11
    Registered User
    Join Date
    07-28-2015
    Location
    Danville, IL USA
    MS-Off Ver
    2013
    Posts
    34

    Talking Re: Combining Two Functions

    Mr. Deitrick,

    JACKPOT!

    I understood how you were trying to force a recalculation by putting the RAND function in, but it didn't work for some reason. So I added an Application.Calculate statement to the end of my Sub Worksheet_Activate() procedure and now it works perfectly with the RAND function in the formula.

    Thank you again for your time and patience.

    ~ Phil White

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Combining Two Functions

    Yay us!

+ 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. Combining multiple functions>lookup/sum functions
    By mush106 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-22-2013, 07:47 AM
  2. Combining two functions
    By ram09 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-24-2013, 01:57 PM
  3. Excel 2007 : Combining functions
    By Petest67 in forum Excel General
    Replies: 2
    Last Post: 03-24-2012, 03:06 PM
  4. Combining If & And functions
    By marielav99 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-27-2010, 10:30 AM
  5. Excel 2007 : Combining IF Functions together....
    By qhx398 in forum Excel General
    Replies: 6
    Last Post: 12-11-2009, 03:35 AM
  6. Combining IF functions
    By NeilM442 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-10-2009, 01:02 PM
  7. Combining IF functions
    By rlkerr1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-14-2007, 03:20 PM
  8. Combining IF & AND functions
    By Khoshravan in forum Excel General
    Replies: 1
    Last Post: 08-04-2006, 12:16 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