+ Reply to Thread
Results 1 to 17 of 17

Macro used to work and now does not

  1. #1
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Macro used to work and now does not

    Hi. I found a Macro on bitesizebio that Mr. Hengen was nice enough to provide.

    I was using it to make a heat map and it was working fine, then one day,
    it stopped working and I received the following error: Variable Not Defined (referring to 'rangetocheck')
    I tried defining 'rangetocheck' as a range but then I get an error code: Variable not defined (referring to 'cell' in the 'For Each cell In Myrange' line)

    Can any one tell me what happened to this macro? And why it worked one day but not the next?

    Please Login or Register  to view this content.
    Thanks so much

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Macro used to work and now does not

    It looks like rangetocheck is supposed to be the title (albeit a strange one) of the inputbox. Is it supposed to be a variable that stores the string for the input box? Or is the title supposed to be "rangetocheck"?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Re: Macro used to work and now does not

    Thanks Solus.

    I think it was supposed to be the input box variable. So, I defined that as a string but now I'm getting the same error message but for 'Cell.' I've never had to define Cell as a variable in VBA. Any suggestions for that?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro used to work and now does not

    I did not get an error?
    May be try to get rid of the inbox, instead choose the selection manually

    Please Login or Register  to view this content.

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro used to work and now does not

    It seems you have Option Explicit at the top of the module now but didn't before. Add:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Re: Macro used to work and now does not

    Hey AB33.

    Maybe my excel's broken. I'm running this, I even removed the text box section, and I'm still getting an error that 'Cell' is not defined.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro used to work and now does not

    Please refer to post #5

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro used to work and now does not

    "I've never had to define Cell as a variable in VBA. Any suggestions for that? "
    If you have option explicit at the top of your code and you use a variable which is not defined, you will get the error you are getting.

  9. #9
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Macro used to work and now does not

    Quote Originally Posted by Trevasaurus View Post
    Thanks Solus.

    I think it was supposed to be the input box variable. So, I defined that as a string but now I'm getting the same error message but for 'Cell.' I've never had to define Cell as a variable in VBA. Any suggestions for that?
    Believe it or not Cell is not an object in VBA. Cells is a collection, but to refer to one "Cell" as you are attempting to do you have to define the variable (the word Cell is now a variable) as a Range. The experts have pointed out it is probably because now the VBE has option explicit turned on which requires you to declare all variables, and their solutions should get you fixed up.


    e/ On a side note, even with option explicit turned off it is good idea to fully qualify all variables by defining them and assigning a proper data type.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro used to work and now does not

    Xero,
    Believe it or not Cells is not an object, nor a collection in VBA.
    Cell is simply a range object that consists of just one element.
    Last edited by AB33; 08-20-2013 at 12:49 PM.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro used to work and now does not

    As Xero said, Cells is a Collection. Cell is just a variable - it has no intrinsic meaning other than as defined in any given piece of code.

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro used to work and now does not

    Rory,
    This statement is from J Walk's book
    "Notice That I wrote cells property, not cells object or even cells collection. Although cells may seem like an object(or a collection), it is not really".
    Last edited by AB33; 08-20-2013 at 03:34 PM.

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro used to work and now does not

    I know what you mean (although you said Cell, not Cells ) but in terms of its behaviour Cells is effectively a Collection, at least as far as the compiler is concerned - in much the same way that Rows and Columns are, even though they theoretically all simply return Range objects.

  14. #14
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655
    Last edited by Solus Rankin; 08-20-2013 at 02:24 PM. Reason: misinformation

  15. #15
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro used to work and now does not

    That's Word, though.

  16. #16
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Macro used to work and now does not

    Sorry I was on my phone. I suppose cells is a property.


    e/ That's why you guys are the experts
    Last edited by Solus Rankin; 08-20-2013 at 02:30 PM.

  17. #17
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Re: Macro used to work and now does not

    Hey. I copied this macro from its module to the code window in 'this workbook' and it worked.
    I think the macro not working was just excel malfunctioning.

    thanks for all the help.

+ 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] Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-27-2013, 11:55 AM
  2. [SOLVED] How to make the macro work for all rows in the work sheet
    By Valli nayaki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2013, 10:43 PM
  3. MAcro does not work when certain cells in a work sheet are protected
    By Unnati in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2012, 03:38 AM
  4. Macro to collate data from different work books and different work sheets
    By bvdileep in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2012, 05:34 AM
  5. Replies: 2
    Last Post: 07-11-2006, 11:15 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