Results 1 to 6 of 6

VB: run-time error '1004': Application-defined or object-defined error

This is a discussion on VB: run-time error '1004': Application-defined or object-defined error within the Excel Questions forums, part of the Question Forums category; Hi, I just started using VB to create macros in Excel recently and I could really use some help. This ...

  1. #1
    ABS
    ABS is offline
    New Member
    Join Date
    Aug 2011
    Posts
    2

    Default VB: run-time error '1004': Application-defined or object-defined error

    Hi,


    I just started using VB to create macros in Excel recently and I could really use some help.


    This macro is intended to go through a column of identifiers in one worksheet (OrgNameMatches) and for each cell search if there is a matching identifier in another column in another worksheet (OrgFacilityRelationship) of the same file. If there is a match, then a hyperlink is to be created between the identifier from OrgNameMatches to the identifier in OrgFacilityRelationship.


    I have the following code so far… (The Run-time error '1004': Application-defined or object-defined error occurs after the following lines:


    Sheets("OrgFacilityRelationship").Select
    Range("A2").Select lines


    Code:
    Sub orgFacilityLink()
     
    Sheets("OrgNameMatches").Activate
    Sheets("OrgNameMatches").Select
    Range("A2").Select
     
    Do Until Selection.Offset(1, 0).Value = ""
     
    varIdMatch = False
    varIdValue = ActiveCell.Value
    varIdRow = ActiveCell.Row
     
    Sheets("OrgFacilityRelationship").Activate
    Sheets("OrgFacilityRelationship").Select
    Range("A2").Select
     
    Do Until Selection.Offset(1, 0).Value = ""
     
    If Selection.Value = varIdValue Then
     
    varIdMatch = True
    varIdMatchRow = ActiveCell.Row
    Exit Do
     
    End If
     
    Selection.Offset(1, 0).Select
     
    Loop
     
    Sheets("OrgNameMatches").Select
    Range("A" & varIdRow).Select
     
    If varIdMatch = True Then
     
    ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="Sheet3!A" & varIdMatchRow, TextToDisplay:=varIdValue
     
    End If
     
    Selection.Offset(1, 0).Select
     
    Loop
    End Sub




    If anyone can please help to resolve the run-time error or if you can point out any other problems with my code, I would greatly appreciate it. Thanks!
    Last edited by Smitty; Aug 5th, 2011 at 02:13 PM. Reason: Added Code Tags - Moderator

  2. #2
    Board Regular
    Join Date
    Jul 2006
    Location
    Brussels
    Posts
    7,645

    Default Re: VB: run-time error '1004': Application-defined or object-defined error

    Quote Originally Posted by ABS View Post
    Sheets("OrgFacilityRelationship").Select
    Range("A2").Select
    You're sure that you do not have a typo in that sheet name?
    That sheet exists in the Active Workbook?
    Regards,


    Wigi


    Excel MVP 2011-2014



    For more Excel memes: visit http://www.wimgielis.be ==> English articles ==> Excel memes

    -- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --

  3. #3
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    26,302

    Default Re: VB: run-time error '1004': Application-defined or object-defined error

    I think you should check where you have that code.
    That error looks to me like it would result if you had the code in the OrgNameMatches sheet module.
    As it stands, the code would need to be in a standard module, not a worksheet module.
    Hope this helps, good luck.
    Peter

    - Read: Posting Guidelines, Forum Rules & FAQs
    - Want to post a small screen shot? Try one of these Excel jeanie, MrExcel HTML Maker or Borders-Copy-Paste (To test: Test Here)
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the VBHTML Maker

  4. #4
    ABS
    ABS is offline
    New Member
    Join Date
    Aug 2011
    Posts
    2

    Default Re: VB: run-time error '1004': Application-defined or object-defined error

    Yes, that was exactly the problem. Thank you very much for your help. Works like a charm now.

  5. #5
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    26,302

    Default Re: VB: run-time error '1004': Application-defined or object-defined error

    Quote Originally Posted by ABS View Post
    Yes, that was exactly the problem. Thank you very much for your help. Works like a charm now.
    No problem, and thanks for the feedback.

    Also, a belated 'Welcome' to the MrExcel board!
    Hope this helps, good luck.
    Peter

    - Read: Posting Guidelines, Forum Rules & FAQs
    - Want to post a small screen shot? Try one of these Excel jeanie, MrExcel HTML Maker or Borders-Copy-Paste (To test: Test Here)
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the VBHTML Maker

  6. #6
    New Member
    Join Date
    Jan 2014
    Posts
    1

    Default Re: VB: run-time error '1004': Application-defined or object-defined error

    Thank you very much! I also found this very helpful!
    Quote Originally Posted by Peter_SSs View Post
    I think you should check where you have that code.
    That error looks to me like it would result if you had the code in the OrgNameMatches sheet module.
    As it stands, the code would need to be in a standard module, not a worksheet module.

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com