+ Reply to Thread
Results 1 to 7 of 7

#REF error that I can't figure out

  1. #1
    Registered User
    Join Date
    10-08-2012
    Location
    NC
    MS-Off Ver
    Excel 2013
    Posts
    39

    #REF error that I can't figure out

    I'm really stuck on this one. I have an error that consistently repeats, and I'm not sure how to keep it from happening. I'm not so sure it's anything with the code, but rather something with the way Excel runs.

    The file that contains this error is attached. In a nutshell, the program creates a graphical time schedule by selecting a persons name. It does this by searching through a database of information and copying every instance that is associated with that name. The code then selects the block of time through a range of cells, merges the cells, and pastes the course information in the cells. You simply choose another name to create a schedule for someone else (and the program in-between unmerges and clears the cells, etc.). The user can then click on any empty cell to fill it in as another type of hour (office, online, etc.). When you open the file it opens to a page with instructions on how to use it. It works perfectly every single time with the exception of one specific name. To create this error, simply go to the "Graphical Schedule" tab, choose the name 'Douglas Mabry' and click "Create Schedule". I would recommend you choose a couple of other names first to see how the software works. Once you've chosen the name that gives the error, you'll see that the error is a #REF error in the total hours areas. These errors are being carried over from another worksheet called "Office Hours", and although I hide this sheet typically I left it visible so it would be easily found. There are several other worksheets that can be "unhidden" if needed.

    The "Office Hours" worksheet is the sheet that tallies the total hours other than classes (such as the above-mentioned office, online and so-on). Thus it directly references the cells on the "Graphical Schedule" worksheet. Now... as mentioned before, some of the cells on the "Graphical Schedule" worksheet get merged, and I could see where this might throw a #REF error (for instance, if cells A14:A17 are merged and a formula was referencing A16, would that throw a #REF error?). However, this doesn't happen with any other name you choose, and they reference cells that are "merged away". So why do I get the #REF error for this user?

    Would the easiest thing be to create some type of error handling? Right now, if that name is chosen, the #REF errors are there to stay. You have to close and reopen the spreadsheet to be able to create schedules for another user (assuming you didn't save the file with the #REF error, in which case you're really stuck).

    NOTE--the worksheets automatically password protect themselves to keep someone from accidentally overwriting formulas. I also protect the workbook. The password to unprotect any of the sheets, VBA code, etc., is 5,4,3,2,1 (just the numbers... no commas).
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,688

    Re: #REF error that I can't figure out

    To diagnose this I need to unprotect sheet "Office Hours". 54321 is not the correct password for this sheet.

    I suspect the problem is related to all the merging. Merging is discouraged for this reason. The root cause, formula-wise, is the #REF! errors on Office Hours. I cannot copy and paste the formula due to the protection, but the formula has #REF! embedded which usually indicates that the row or column of the cell it originally referred to has been deleted. In cell E25 there is a reference that looks like it was originally to 'Graphical Schedule'!E28. Some action in the code did something to E28 which made the reference invalid. It is possible that is related to merging/unmerging.

    All of the protection and restrictions make it difficult to troubleshoot this. I had to change a lot of code just to be able to evaluate results after running it.

    In the future when you create VBA that make your file into an app, a good practice is to build in a "developer" mode which will unprotect everything and show all sheets. This has to be woven into the code, harder to add after the fact.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-08-2012
    Location
    NC
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: #REF error that I can't figure out

    6String--

    I'm not sure why the password isn't working for you... wait! That password WAS different so I've unprotected it and will re-upload the file here. Also, I didn't protect the workbook, so it's already unprotected. As for the protections and unprotections, I've never made something like this before, but every time I have to do anything it's a real pain. I realized the need for such a developer utility!

    What other options could I use instead of merging cells? I tried using textboxes instead, but even with code pulling them to the corners the alignment didn't look the greatest. Is there some way to make them look merged without actually merging them?
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: #REF error that I can't figure out

    Quote Originally Posted by JonathanEngr View Post
    Is there some way to make them look merged without actually merging them?
    Didn't look at your file, but if you're merging cells within the one row, an alternative is Center Across Selection

    doc-center-text-3.png
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Registered User
    Join Date
    10-08-2012
    Location
    NC
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: #REF error that I can't figure out

    I think the reason I did the merge is to eliminate interior borders, but since I'm selecting the range I can simply do an outer border only...

    Okay... I have also read that selecting a range, etc., through VBA is bad practice (throws errors if the sheet is protected), so in my code I set a range. The range of the cells that are merged is called "rngClassb". Once I have established that range, here is my code:

    Please Login or Register  to view this content.
    You can see where I unprotect the sheet and begin setting my text alignment, followed by merging the cells. I set the border (which will only border the outside since the cells are merged). The color of the merged cell(s) are set and the text is pasted into the cell. The sheet is once again protected and the code loops (if necessary). If I drop the merge portion of the code, setting the color of the cells should remain the same, and I can research setting the border to outside only. However, how do I replace the vertical and horizontal "centered" alignment with "center across selection" to make the text centered vertically and horizontally? Everything I see about "center across selection" is for centering over several columns--not rows. I need to center the text in several rows over a single column (such as A25:A28).
    Last edited by JonathanEngr; 04-15-2018 at 02:20 PM.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,688

    Re: #REF error that I can't figure out

    OK here's your problem. Mabry has two classes that overlap the same half-hour slot on Thursday from 8:00-8:30. When you create the second one on the schedule, the merging gets all screwed up because your merged range overlaps into another range that is already merged. That causes the REF errors on your Office Hours sheet, which ripples back into your schedule sheet.

    First class

    "AHR 114 D02
    8:15 PM -9:35 PM
    PTI 123"

    Second class

    "AHR 210L D02
    6:30 PM -8:07 PM
    PTI 119"

    You cannot center text vertically without merging, but if you merge you are going to get problems like this. Pick your poison.

    Personally I would avoid merging. If you always use at least three rows for each class, use those for the three lines of text. Show the block with a color and border.

    If you merge you are going to have to have a check in your code for an overlap like this. Then unmerge the top one, and remerge it without the bottom cell. Then proceed to merge the secodn one.

  7. #7
    Registered User
    Join Date
    10-08-2012
    Location
    NC
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: #REF error that I can't figure out

    There was code to handle when classes overlap:

    Please Login or Register  to view this content.
    I can't honestly say I completely understand exactly what the code does, but someone on the forum suggested this code due to merged areas combining when there was an overlap. Hmmmm... I guess I could always check the database to make sure that times don't overlap. Perhaps have one set of times that are put into the cells, and another set that will be rounded and used to set which cells are highlighted that make sure they don't overlap.

    As for # of cells for classes, many classes just use two cells--not three. I'll have to think on this and see how to approach it. It's unfortunate that you can't vertically "align text over range of cells", but it is what it is. It's also unfortunate that text boxes don't align perfectly to a cell range. Any specific suggestions on how to handle this would be welcome!

+ 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. Getting #N/A error can't figure out why
    By SimonLee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-22-2014, 04:38 AM
  2. Replies: 4
    Last Post: 02-03-2014, 08:05 AM
  3. [SOLVED] #NAME? Error, cant figure out why.
    By Speshul in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-08-2013, 01:06 PM
  4. [SOLVED] VBA error I cant figure out
    By Peltz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-20-2012, 05:12 PM
  5. Error I cannot figure out
    By Antonio in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2006, 10:40 AM
  6. [SOLVED] error 400, i cant figure this out..
    By Michael A in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-06-2005, 08:06 PM
  7. [SOLVED] Some Error that I can't figure out.
    By Mcobra41 in forum Excel General
    Replies: 1
    Last Post: 02-28-2005, 08:06 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