+ Reply to Thread
Results 1 to 16 of 16

How to get referenced cell to be recognized by macro

  1. #1
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    How to get referenced cell to be recognized by macro

    I'm not sure what I'm even using is a macro, but I got it to kind of work. If a cell N1 on the worksheet contains a variable number 1-50 (signifies number of people), it will figure out what cells to unhide (will print like 9 people per page). I got it working correctly, the problem is when the cell that is being referenced (the one with the variable number) pulls the number from another worksheet (e.g. ='DATA SHEET'!I54), it does not update like when I manually type a number into that cell.

    Here's the formula I'm using to display the cells I want:

    Please Login or Register  to view this content.
    Can anyone tell me how to get this to work right?

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to get referenced cell to be recognized by macro

    What is the name of the sheet that contains this code, what is the name of the sheet that gets rows hidden and what is the name of the sheet that contains the cell that will contain the information used in the Selection process?

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    The name of the sheet that contains the code and has the rows hidden is "IJ1"
    The name of the sheet that contains the data is "DATA SHEET"

    Cell in N1 on Sheet IJI pulls data from cell 'DATA SHEET'!I54

    Reading this, it's a "change event" where my manual input does what I want it to do, but whenever the value of any cell on the worksheet is changed by the result of a formula calculation, it doesn't work.

    So, hoping that someone has some kind of work around like select the cell, then hit enter whenever the tab is selected. (No data needs to be input or manipulated on this worksheet.

    Thanks

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to get referenced cell to be recognized by macro

    Try this (untested):

    Put this code in Sheets("DATA SHEET")

    Please Login or Register  to view this content.
    abousetta

  5. #5
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    Still doesn't seem to work. The variable number is not something manually input anywhere, it's a the result of a formula. The data sheet takes information from other sheets and compiles it onto that sheet. Then the IJ1 sheet (and IJ2 sheet), pull from that sheet. I haven't messed around with pivot tables much, but there was an auto-update of the pivot cache which would refresh that data when clicking on the tab. I read somewhere about adding a calculate function that may work, but couldn't find any examples. I wonder if having it calculate the the original number +0 would work?

  6. #6
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: How to get referenced cell to be recognized by macro

    It should be
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    Still not working. It only hides the rows when I manually change the numbers on the IJ1 page and tab out or hit enter.

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to get referenced cell to be recognized by macro

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  9. #9
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: How to get referenced cell to be recognized by macro

    It should work if you are changing the value in Sheets("DATA SHEET").Range("I54").

    Is this cell containing a formula as well?

    If so, what data, and in where, are you changing? Is the change manual or with a macro?

    The solution lies in putting the code into where the source data is updated/changed.

  10. #10
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    I54 is a formula too. It's =COUNTIF($A$2:$A$51,I2)
    A2:A51 is column that has Text - (A Person's Names). The names (Think Boss name, and the columns to the right are subordinate info) are pulled from 2 other sheets (Up to 25 Names Per Sheet - total of 50 rows). So the sum of the value of each name determines how many pages to show. If the Boss' Name has 45 people under him/her, I'd need like 5 or six pages to show.

    I'm pretty sure I could do what I want with a Macro, but I was hoping to to just make it seamless. The only thing the end user should be typing in is the boss name, employee name and a few other details (Start time, Floor #, etc.). Another employee would go to the excel file, click on the IJ1 tab (or whatever I eventually name it) and see only the needed rows that contain data.

  11. #11
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: How to get referenced cell to be recognized by macro

    Try amending abousetta's code. This should fire the change event as the Boss' names are being entered.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    Still not having much luck. I'll try to break it down and upload a sample.

    Thanks all for trying.

  13. #13
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    Okay, here's the workbook.

    Data is manually entered in sheets "List One" and "List Two."

    The data is pulled onto the data sheet and sorted.

    IJ1 or IJ2 (I'm really only accounting for 2 bosses even though the Data Sheet sorts up to 3) is then accessed by an employee and prints out the worksheet. Rows corresponding to page numbers should be hidden based on the the numbers that have already been listed. I had a change code on each sheet that would do what I wanted if I manually typed the number into cells N2 on IJ1 and IJ2, but that code has been removed and instead replaced with what was provided on the data sheet.

    I'm thinking the code needs to be on Sheets List One, and List Two since that's where the info is manually being typed, just not sure how to modify it. Then, would say Sheet IJ2 need to look at a different cell reference to not be confused with the number on the other sheet?
    Attached Files Attached Files

  14. #14
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to get referenced cell to be recognized by macro

    This is why I don't like change events...

    In DATA SHEET, put this code:

    Please Login or Register  to view this content.
    It turns out that Worksheet_Change is only triggered if the worksheet is the active sheet (so can't use similar code in the "IJ1" sheet). Also Select/ Case/ End Select keeps checking all the possible cases even if finds the one meeting it's needs. Therefore the number 1 is less than 9, 18, 27, etc. and so all the rows become visible. I changed it to IF/ ElseIF to get around this issue.

    Let me know if you have any further problems.

    abousetta

  15. #15
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    Tried to incorporate the before mentioned with no luck. However, I did get this work-around to have it do what I want. I made a marco that simply copy and pastes (value) to the cell I needed the number in. I made cell M2 pull the number from the data sheet using. Since M2 it is a formula and doesn't affect change events, I just had the macro auto-run when the sheet was select which pasted the value to cell N2 (the reference cell). That seems to trigger the change event and the rows are auto adjusted.

    Please Login or Register  to view this content.
    Last edited by kspeese; 12-20-2013 at 06:49 PM.

  16. #16
    Registered User
    Join Date
    11-20-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: How to get referenced cell to be recognized by macro

    Now that the sheet looks correct, is there a way to set the print area to correspond what is shown? Like if the number was 15 and it's only displaying 2 pages (Rows 1:92) (& Pages 3-6 are hidden), to only print the 2 pages if someone chose to select print?

    Like: ElseIf Rng.Value <= 18 Then
    .Rows("3:92").Hidden = False 'Page 2
    ActiveSheet.PageSetup.PrintArea = "A1:J92"

+ 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. Replies: 14
    Last Post: 09-04-2013, 12:01 PM
  2. macro: insert specified number of rows depending on referenced cell value
    By cffurillo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2012, 11:37 AM
  3. Macro button to separate workbook as a file name referenced from cell.
    By Moonpie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-09-2012, 12:19 PM
  4. [solved] Macro to apply formatting to each referenced cell of a formula
    By raystafarian in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-01-2012, 02:12 PM
  5. Opening a Folder from Referenced Cell (Macro)
    By narr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 10:34 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