+ Reply to Thread
Results 1 to 17 of 17

Method or data member not found

  1. #1
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Method or data member not found

    Can someone please explain to me what this means please.

    I am trying to change the colour of a cell, and every time (for 6 months now) selecting a single cell with VBA is an issue. How is it done. I have tried this this time. It works in one sub, now I can't get it to work at all:

    Please Login or Register  to view this content.
    Overview is a sheet name and JobNumber is a global string variable.

    I have also tried this:
    Please Login or Register  to view this content.
    And that doesn't work either, what am I doing wrong???

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Method or data member not found

    If Overview is the sheet's name then you should say:

    Please Login or Register  to view this content.
    If you are already in the sheet you can leave that part and just start with Cells
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Method or data member not found

    try using Sheets before sheet name
    Sheets("Overview")
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Method or data member not found

    That works perfectly fine in my excel.

    Shot in the dark, is 'overview' specifically typed as a worksheet variable?
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Method or data member not found

    Quote Originally Posted by YasserKhalil View Post
    try using Sheets before sheet name
    Sheets("Overview")
    overview.Cells(1, 1).Interior.ColorIndex = 50 is totally legit if overview is a worksheet variable, or if that is one of the worksheet's .codeName values.

    You'll only want to do this if you are using the user-viewable tab name (worksheet.name) to access a sheet - which is generally something to avoid because that name may be altered.

  6. #6
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Method or data member not found

    Overview is indeed the sheet name variable, but it is also the name appearing on the tab.
    Ok, so I have a range of cells on this sheet that I named JobID but for some reason it can be accessed in another Sub, but not this one.
    Please Login or Register  to view this content.
    JobID is a named range of the first sheet (Overview) and it's range is I10:BF10. What has changed with these two subs?

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Method or data member not found

    I did some quick corrections but there's still a lot of issue with PrintBOM (as a worksheet?) and the references.

    All sheets musht be either adress though a set variable of Sheet("sheetname")

    I made some changes (see the modified code below)

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Method or data member not found

    Hi,

    The issue is that "Rework" is not available as a range in the second macro, and neither is the named range "JobID" which is named in the sheet itself. why is this happening, surely if declared as either Public at the top of the module or Dim at the top of the Macro, surely it should be there no matter what the sub routine.

    How can I get round this please?

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Method or data member not found

    It's not only that it's the whole worksheet decalration you're using.

    I cannot write it out for you without testing. I do not have anything near to the ranges or worksheets you use, unless you want to attach a sample file with dummy data it will be easier

  10. #10
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Method or data member not found

    Ok, I think I can help.

    @Rob K - code from Post#6.


    Basically, I think you need to alter your thinking on what a Public Variable would do here. Using a Module-level declaration like 'Public Rework As Range' does not get you around the need to "SET" the variable in the button click macro.

    Overview.Rework does not make sense because Rework is not a method or data member of object Overview. Once you have SET rework (with a line like Set Rework = Overview.Range("JobID")) then you can just access it in the code.

    (but read my comment below this block of code)

    Please Login or Register  to view this content.

    BUT! There is an easier way to avoid the need for SETting a variable altogether. Since JobID appears to be a named formula identifying a range (aka named range), you can just go right to it.


    IF the SCOPE of JobID is Workbook (in the name manger), then you can use that name in your VBA with brackets. [JobID].Cells(1, Int(JobNumber)).Interior.ColorIndex = 50 is a perfectly legitimate statement.

    IF the SCOPE is NOT workbook (then it's a specific sheet name, I'll guess "overview" for the name) then you just need to preface the [JobID].cells(... call with the worksheet in one of three ways:

    1) (best) Just use the worksheet codeName: Overview.[JobID].cells(... etc.

    2)(next best) Use an worksheet variable to identify the sheet (but that variable will need to first have been declared and set...):

    3)(worst) Use the worksheet name (different from codename) - this is the 'tab' name the user sees. THIS IS A BAD IDEA because you can't 100% rely on that name not changing.

    worksheets("Overview").[JobID].cells(... etc.


    Well, I guess there is a 4: Sheets(1).[JobID].cells(.... That's the worst-worst of all because it depends on the order of the sheets in the users view, which might be changed also.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Method or data member not found

    Rule of thumb when coding and writing code
    - Always check if a vraiable, range or sheen exist
    - protect the worksheets so that users cannot change them but let the vba code acces it without problem
    - etc. etc.

  12. #12
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Method or data member not found

    Hi there, thanks very much for your comments, but it still doesn't work. This has stumped me for over a week now. I don't understand it, I can change the colour of this cell if this line is in the main macro, but I can't get it to work elsewhere.

    Please Login or Register  to view this content.
    Now gives me an application-defined or object-defined error. I have address the issue of the variable losing value by setting the value to a cell on another sheet, but this is still causing me problems.

    Alternatively, basically, I have a range on the first sheet from "I10:BF10" and this is where the number comes from, this is the range of JobID and all it does is give me a number from 1 to 50.

    How can I make it so that the right cell in this range can be set to green. I can't believe it is that hard to do.

  13. #13
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Method or data member not found

    After a bit of digging, I find the following line:
    Please Login or Register  to view this content.
    Works fine in any sub except the Sub Button_Click(). This leads me to believe that actually my syntax is correct, but I have something else missing. Again "Overview" is the name of the sheet no the caption.

    Why would this be?

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Method or data member not found

    I don't think you're listening to any of us
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Method or data member not found

    That's because:
    Please Login or Register  to view this content.
    Does not work, it doesn't matter if I use the sheet tab name in the syntax you have or whether I use the sheet name which is microsofts recommended practice, see method 10 here http://www.techrepublic.com/blog/10-...ets-using-vba/

  16. #16
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Method or data member not found

    Issue solved. I'm such an idiot. I had "Overview" as protected so the macro could not access it.

    Thanks for your help GeneralDisarray, your comments have been invaluable!

  17. #17
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Method or data member not found

    [QUOTE=Rob K;4140569]I can change the colour of this cell if this line is in the main macro, but I can't get it to work elsewhere.[QUOTE]

    I would guess something is out of scope, but can you post your code with the new alterations?

+ 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] Error: Method or Data Member Not Found
    By k64 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-21-2015, 08:39 AM
  2. Method or data member not found
    By katieshields in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-02-2014, 08:49 AM
  3. Compile Error Method or data member not found
    By ixelister in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2014, 03:39 PM
  4. [SOLVED] error: Method or Data Member not found
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2013, 11:01 AM
  5. Compile Error:Method or Data Member Not Found
    By loknath in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-29-2012, 04:03 AM
  6. Compile Error Method or data member not found
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2005, 06:05 PM
  7. Method or Data Member not Found
    By Syed Haider Ali in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-22-2005, 09:27 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