+ Reply to Thread
Results 1 to 9 of 9

Error vba code 1004

  1. #1
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    149

    Error vba code 1004

    Hi,

    I have the code below in a userform with I click update give me Error 1004 "Application-defined or Object-defined error"


    Here is the code:

    Please Login or Register  to view this content.
    Thank you,

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,696

    Re: Error vba code 1004

    Where is rowselect defined and/or initialised?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Error vba code 1004

    This line start at cell B2 (not sure if this what you mean:

    Please Login or Register  to view this content.

    PHP Code: 
    SAGEID    VENDOR    INVOICE_NUMBER    PO_NUMBER    APPROVER    GL_CODE
    100215    ABC COMM
    .        17786-28380,2862030862    HD    602110-28-500-100 Fixed Data Customer Data ServicesTCOM ONT
    100109    AFX COMMUNICATIONS        80017    MJT    603202
    -28-500-100 LD TF Other TCOM ON
    100433    AIDEN HODSON    TIMESHEET
    -07242022    JUL 11-24-2022    GLEN GREGORY    609113-28-500-100 Prof Services Other Customer billable TCOMON
    100176    AIRSPRING    162072451    JUNE 2022    HD    603220
    -28-500-100 LD Toll DalTCOM -  ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    254259-NOV 2021    254259-NOV 2021    254259-JS    603220-28-500-100 LD Toll DAL TCOM ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    254259-NOV 2021    254259-NOV 2021    254259-JS    323112-08-000-500 HST ITCBC
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    164982-NOV 2021        164982-EK    608110-28-500-100 Fixed Voice Network Access IX TCOM ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    164982-NOV 2021    NOV-2021    164982-EK    608110-28-500-100 Fixed Voice Network Access IX TCOM ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    164982-NOV 2021    NOV-2021    164982-EK    608110-28-500-100 Fixed Voice Network Access IX TCOM ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    164982-NOV 2021    NOV-2021    164982-EK    323112-08-000-500 HST ITCBC
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    17788676        1139885-EK    605150-28-500-100 Local Resold Commercial TCOM ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    17788676    1139885-NOV 2021    1139885-EK    605150-28-500-100 Local Resold Commercial TCOM ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    17788676    1139885-NOV 2021    1139885-EK    605150-28-500-100 Local Resold Commercial TCOM ON
    100053    ALLSTREAM BUSINESS INC
    C/O T4622    17788676    1139885-NOV 2021    1139885-EK    605150-28-500-100 Local Resold Commercial TCOM ON 

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,696

    Re: Error vba code 1004

    Sure. But where do you define rowselect? And where do you give it a value? If it is undefined and you don't set a value, it will be zero or blank or null. Whatever, when you refer to Cells(rowselect, 2) = Me.txtvendor.Value, rowselect won't have a positive numeric value.

  5. #5
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Error vba code 1004

    Sorry not that good in vba not sure what you mean, would it possible explain to me more, please.

    Thank you,

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,696

    Re: Error vba code 1004

    OK. Clearly not explaining this very well. I was hoping to lead you to the answer and there would be a lightbulb moment ... but that isn't happening.

    I honestly don't know if there is anything else wrong with your code because I have no way of testing it. No workbook, no forms, no data, etc.

    So, if you do not define a variable that you subsequently use, it will have a null value and a zero length. If you define a variable as Integer but don't assign a value, it will have a default value of zero ( 0 ) and a length of 2. f you define a variable as Long but don't assign a value, it will have a default value of zero ( 0 ) and a length of 4. The length is interesting but not that important. Generally, if you define a variable to refer to a row number, I would recommend you use type Long.

    When you refer to the variable rowselect in your code, as in:
    Please Login or Register  to view this content.
    rowselect has not been defined and therefore has a null value. So, effectively, your code says
    Please Login or Register  to view this content.
    which is not valid.

    The variable rowselect must have a positive numeric value to be valid when referring to a row number. A null row does not exist. Row zero does not exist. Hence the code breaks.

    You need to a) Dim the variable: Dim rowselect As Long, and b) assign it a suitable value before you use it to refer to a row number.

    If you want to start writing your data out from, say, row 2, you would use:
    Please Login or Register  to view this content.
    As you are using Find to locate a Target, maybe you should be using Target.Row rather than rowselect?

    And also, because you are referring to cells within a With ... End With block, they should have a full stop/period/dot in front of them:
    Please Login or Register  to view this content.
    Some sample code:
    Please Login or Register  to view this content.
    Last edited by TMS; 11-09-2022 at 01:09 PM.

  7. #7
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Error vba code 1004

    Hello Joros. In addition to what was commented by TMS, I would try to add:
    rowselect = Target.Row

    after:
    Set Target = .Range("A:A").Find(.....)

  8. #8
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Error vba code 1004

    Thank you both, TMS and Beyond for all your suggestion. working now.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,696

    Re: Error vba code 1004

    You're welcome. Thanks for the rep.

+ 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. Error 1004 - object-defined error when vba code not applicable
    By SubwAy in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 06-20-2016, 05:20 AM
  2. [SOLVED] Vba code error 1004
    By Nitro2481 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2015, 10:39 AM
  3. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  4. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  5. I get a 400 error or 1004 error depending on where I run the code
    By mouseman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-30-2013, 10:38 AM
  6. [SOLVED] Getting Error 1004 Object or Application Defined Error - Code to rearrange data
    By BlazzedTroll in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-10-2013, 12:10 PM
  7. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03: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