+ Reply to Thread
Results 1 to 8 of 8

Referencing same cell on different worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    02-28-2008
    Posts
    8

    Referencing same cell on different worksheet

    After lots of help from mikerickson on cell adjacency, I'm back with another problem..!

    I have a workbook with several sheets, some with fixed cell values and some with values that change.

    I've adapted a code from mikerickson that allows me to create a UDF called lighttest which looks at the value of a cell and then takes one of several options.

    Function lighttest (ByVal mastercell As Range) As Double
    
    Application.Volatile
    
    If mastercell.Value = 3 Then
    
    lighttest = WorksheetFunction.Sum(masterCell.Value, Worksheets ("daylight input").[A1])
    
    Else
    
    If masterCell.Value = 2 Then
    
    lighttest = masterCell.Value
    
    Else
    
    If masterCell.Value = 1 Then
    
    lighttest = WorksheetFunction.Sum(masterCell.Value, 5)
    
    End If
    
    End If
    
    End If
    
    End Function
    The code works fine as it is but I'd like to change the option for the value 3, so that it sums the active cell on the main sheet 'mastergrid' with the same cell on the sheet 'daylight input' (rather than cell A1), and ideally, the same cell on other worksheets too.

    I tried replacing [A1] with [masterCell] but I keep getting #VALUE! errors

    Any help would be gratefully received
    Last edited by VBA Noob; 03-01-2008 at 06:59 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    What do you mean by "activecell"? The cell on the active sheet that is currently selected (dangerous if you move about the sheet), or a specific cell on the main sheet?

    Can you be a bit more specific on exactly what cells, from what workbooks you want to action.


    rylo

  3. #3
    Registered User
    Join Date
    02-28-2008
    Posts
    8

    Re: activeCell

    Hi,

    I've attached a file that should explain it more...

    The grid on the left represents what I've called mastergrid, each cell will change values between 3, 2 and 1

    The sheet "daylight input" is a grid of fixed values.

    Essentially, I want to iterate through variations to the mastergrid based on the results of the UDF "lighttest".

    Hopefully, the cells containing 3's and 1's on the mastergrid will tend to move towards the equivalent higher values on the "daylight input" sheet.

    The function is cell specific so each cell contains a reference to a cell on the mastergrid. The upper right grid illustrates this principle, using the function I posted earlier (eventually it will be placed on a separate sheet)

    The lower right grid contains the formula
    =SUM('mastergrid:daylight input'!A1)
    where 'A1' is different for each cell, which is fine except I would like this to be an IF function that only sums the result if the value of mastergrid is 3 (i.e. if it = 2 I'd like it to do nothing, and if it = 1 I'd like it to add 5)

    I think I probably just need another sign or Chr(34) or something in the function I have, it's just hard to find a solution in the help files...
    Attached Files Attached Files
    Last edited by archipelago; 03-01-2008 at 09:22 PM. Reason: forgot to add attachment

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Please don't use the post icon -- it is what spammers use, and likely to be inadvertently deleted by a mod.

  5. #5
    Registered User
    Join Date
    02-28-2008
    Posts
    8

    sorry for the post icon

    Apologies shg,

    The post icon was completely accidental.

    I spent so long composing that post that it even logged me out at one point, I must have clicked the post icon when I hit tab or something.

    Lesson learned, I'll try and avoid writing posts at 1am in the future!

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    No harm done, thank you.

+ 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