+ Reply to Thread
Results 1 to 6 of 6

Variable Error '1004' - Application-defined or object-defined error

  1. #1
    Registered User
    Join Date
    08-25-2014
    Location
    Atlanta, GA
    MS-Off Ver
    2010
    Posts
    6

    Variable Error '1004' - Application-defined or object-defined error

    I wrote the following code and am trying to use a variable as the lookup value in a vlookup function. But, every time the macro runs, an error occurs with the variable bolded below.

    Does anyone know why this is occurring and how to fix it?


    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim cellvalue As Variant
    cellvalue = Format(ActiveCell.Offset(0, -1).Value, "00000000000")

    If Not Intersect(Target, Range("A10:A110")) Is Nothing Then
    Target.Offset(0, 1).ClearContents
    ActiveCell.Formula = "=vlookup(" & cellvalue & ",'Project # and Name'!A1:B2,2,FALSE)"
    End If

    End Sub


    Thank you!!

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Variable Error '1004' - Application-defined or object-defined error

    You're changing values in Column A? Offset(0, -1) means zero rows and one column to the left of the Active Cell, which if it's in column A doesn't have anything to the left of it, so it will throw an error.

  3. #3
    Registered User
    Join Date
    08-25-2014
    Location
    Atlanta, GA
    MS-Off Ver
    2010
    Posts
    6

    Re: Variable Error '1004' - Application-defined or object-defined error

    Ah, that would be it. I thought I tested to see which cell became the active cell once the Target.Offset(0,1).ClearContents line was completed. I had a message box pop up and I thought it said B2, but I guess I was mistaken. Thanks for catching that!

    As a follow up question, the value in the active cell is going to be input as C0000000001, C0000000002, etc (basically starting with a letter and then followed by ten digits. The problem is that the code is chopping off the zeroes and thinks I'm referring to a cell name, such as C1 or C2 instead of the text string in the active cell. I had researched this earlier and was told that the Format function would correct this, but it doesn't seem to be. I've also tried inputting a Text function in the vlookup around the cellvalue variable, but it didn't work either.

    Do you have any suggestions for that?

    That seems to be the final problem standing in the way of this working correctly...for now at least.

  4. #4
    Registered User
    Join Date
    08-25-2014
    Location
    Atlanta, GA
    MS-Off Ver
    2010
    Posts
    6

    Re: Variable Error '1004' - Application-defined or object-defined error

    Ah, that would be it. I thought I tested to see which cell became the active cell once the Target.Offset(0,1).ClearContents line was completed. I had a message box pop up and I thought it said B2, but I guess I was mistaken. Thanks for catching that!

    As a follow up question, the value in the active cell is going to be input as C0000000001, C0000000002, etc (basically starting with a letter and then followed by ten digits. The problem is that the code is chopping off the zeroes and thinks I'm referring to a cell name, such as C1 or C2 instead of the text string in the active cell. I had researched this earlier and was told that the Format function would correct this, but it doesn't seem to be. I've also tried inputting a Text function in the vlookup around the cellvalue variable, but it didn't work either.

    Do you have any suggestions for that?

    That seems to be the final problem standing in the way of this working correctly...for now at least.

  5. #5
    Registered User
    Join Date
    08-25-2014
    Location
    Atlanta, GA
    MS-Off Ver
    2010
    Posts
    6

    Re: Variable Error '1004' - Application-defined or object-defined error

    Oh, wait, I just tried ActiveCell.Address in place of the cellvalue variable and it's working correctly now!

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Variable Error '1004' - Application-defined or object-defined error

    Glad you got it working. Please mark this thread as SOLVED (instructions below). And any reputation points (the star in the lower left of my posts) is appreciated.

    To mark solved:
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

+ 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. Replies: 5
    Last Post: 08-19-2015, 07:10 PM
  2. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  3. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  4. [SOLVED] Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax
    By winch in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-04-2013, 11:02 AM
  5. [SOLVED] run-time error '1004' application-defined or object-defined error - Excel 2007
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 02:46 AM
  6. Replies: 2
    Last Post: 09-12-2012, 01:01 PM
  7. Replies: 0
    Last Post: 05-14-2012, 11:59 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