+ Reply to Thread
Results 1 to 7 of 7

Coding Error I can't fix

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Coding Error I can't fix

    The following code gives an "Application Defined or Object defined" Error, at the line .Range(Cells(r,4+b)).Value = SupergangAr(4,a). All the addresses are correct and contain values.
    I think my coding must be wrong but I can't see why.
    Can anyone help please.
    Please Login or Register  to view this content.
    Thanks in anticipation
    John

  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,721

    Re: Coding Error I can't fix

    The Cells reference is associated with a sheet. In this case is it unqualified, therefore will default to the active sheet, which may not be the same as sheet Order. You cannot refer to a range in Order that references Cells from a different sheet.

    Add a dot in front of Cells.
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Coding Error I can't fix

    Six string,Thanks for your interest.
    I have modified the code to:-
    Please Login or Register  to view this content.
    To make sure that r was not a string and to add your qualifying dot. Same error message though.
    All the variables have expected values.
    John
    Last edited by 6StringJazzer; 08-04-2015 at 11:02 AM. Reason: fixed code tags

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

    Re: Coding Error I can't fix

    Quote Originally Posted by j_Southern View Post
    All the variables have expected values.
    What are the expected values? Specifically, what are the values of r, b, a, and SuperGangAr(4, a) at the point where the error occurs?

    In general I would also suggest that you use Option Explicit and declare all variables. It appears that you allowing them to default to Variant. This may not be causing your problem but when you say that you use CInt to make sure r is not a string, it suggests there could be typing issues.

  5. #5
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Coding Error I can't fix

    I take your point about not declaring variables. It is a bad habit I have got into.
    I will rewrite with everything declared just in case

    r= 4
    b = 1
    a = 0
    SuperGangAr(4,a) = "Gang1"

    John

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

    Re: Coding Error I can't fix

    If the cell referred to by .Cells(r, 4 + b) doesn't contain either the address or name of another range, you will get an error. If you're just trying to refer to that cell, use just:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  7. #7
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Coding Error I can't fix

    RomperStomper,
    Thanks for your advice, which was the answer to my problem. I don't fully understand the use of .Cells(.... and Range.Cells(.... so that's more homework to do.
    I do think that this forum (and its gurus and experts) is a wonderful help to beginners like me. Thanks again
    John

+ 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. VBA Coding Error
    By amconner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2015, 02:06 PM
  2. Coding Error - VBA
    By sgp in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-13-2011, 08:15 AM
  3. Error while coding to add the row ?
    By vumian in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-29-2008, 11:59 AM
  4. [SOLVED] VBA Coding Error
    By sdg8481 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-25-2006, 11:10 PM
  5. [SOLVED] Help with coding error
    By carlos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2006, 06:45 AM
  6. [SOLVED] Excel Coding Error!
    By Killer in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-23-2006, 08:55 PM
  7. coding error
    By tom mcdonald in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-16-2005, 11:04 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