+ Reply to Thread
Results 1 to 12 of 12

Error 1004 "Application-defined or Object-defined error" when selecting a range.

  1. #1
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Error 1004 "Application-defined or Object-defined error" when selecting a range.

    Hi,

    I am running into the Error 1004 "Application-defined or Object-defined error" when selecting a dynamic range

    Please Login or Register  to view this content.
    The error is on the line "db.Range(FCST1, db.Cells(lr1, lc1)).Select"

    the above code is for one table and I have three more tables to use a similar code on.

    I am not sure what is causing the issue. I referred to several solutions online but nothing seem to work. I am trying to add borders for dynamic tables with data. Tables are created using a different set of codes and they are distributed in one sheet, each table starting from first cells of different columns.

    Thanks in advance
    For ex: table 1 start at "A1", table 2 at "D1" and so on.

    I also have tried the commented codes above but still got the same error code on the same line.
    Last edited by Vj Raj; 08-04-2021 at 03:57 PM.

  2. #2
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    I also have tried the commented codes above but still got the same error code on the same line.
    Last edited by Vj Raj; 08-04-2021 at 03:58 PM.

  3. #3
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    When I used the commented code lines, i got the error "Method 'Range' of object'_Worksheet' failed". I tried changing End(xlUp) and End(xlToLeft) to End(xlDown) and End(xlToRight), still the same error

  4. #4
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    where is db declared?
    What is db? Range, Workbook?
    If you find the suggestion or solution helpful, please consider adding reputation to the post.

  5. #5
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    The code that I've posted is part of a longer set

    db is a worksheet and I have defined that at the very beginning. That is why you don't see it in the line i posted. It is being used for other functions before I run the codes posted above.

  6. #6
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    So if you put a break point on that line that is giving you the error:
    The error is on the line "db.Range(FCST1, db.Cells(lr1, lc1)).Select"

    so that the code stops and you check all the values in the variables above, are they all populated? And if they are, are they valid?


    FCST1 = ??
    lr1 = ??
    lc1 = ??

    I would make sure that what you are passing into that range, is valid values..

  7. #7
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    Just to make sure I explained the logic clearly,

    FCST1 and FCST 2 are ranges which points to the very first cell of each table.

    lr1 and lc1 are used to define the range of the entire table with values. basically trying to replicate ctrl+shift+right and down, so that I can select the table till the last row and column with values only, ignoring the blanks. Then adding borders. This is what I am trying to achieve, if that makes sense.

    To summarize: my goal is to select the table with rows and columns containing only value and ignoring blanks and then add a border around the table. Also, mind that the table is dynamic.

    I've attached a sample file explaining what I want to achieve
    Attached Files Attached Files
    Last edited by Vj Raj; 08-04-2021 at 04:52 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    I understand what you are trying to do, but im just asking if those variable that should be containing valid values for the range to be selected, are they being populated with the correct range values?

    Since its getting the error here: db.Range(FCST1, db.Cells(lr1, lc1)).Select to me its telling me that maybe a invalid value was passed into that Cells() portion..
    Last edited by cubangt; 08-04-2021 at 04:56 PM.

  9. #9
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    I am not sure how to check that. If you are referring to the table itself, I do see values. I am new to VBA, I'm not really sure what is causing this issue at this point. I also am not sure on how to modify the code to make it work.

  10. #10
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    In your VBA editor, if you place a break point on the line i show in the screenshot, run the code and it should stop there.. once it stops, mouse over the variable above that line to make sure that the correct row and column are being passed into that line..

    Also just noticed, that your lc1 is commented out, maybe uncomment that first and see if it works..(may be that simple, you are using the wrong variables in the Cell() portion)
    Attached Images Attached Images

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    It's what happens when using useless variables, you are confusing yourself …

    Quote Originally Posted by Vj Raj View Post
    To summarize: my goal is to select the table with rows and columns containing only value and ignoring blanks and then add a border around the table.
    So according to your post #7 attachment - which should be in the initial post … - a VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
            
    Dim Rg As RangeN%
            
    Application.ScreenUpdating False
        
    For Each Rg In Sheet1.UsedRange.SpecialCells(2).Areas
        
    For 7 To 10
            Rg
    .Borders(N).Weight xlMedium
        Next N
    Rg
            Application
    .ScreenUpdating True
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-05-2021 at 07:18 AM.

  12. #12
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Error 1004 "Application-defined or Object-defined error" when selecting a range.

    Marc L. Thank you for providing me the code. It worked like a charm. I am sorry for confusing you guys, I am totally new to VbA and trying to use "Record Macros" option and edit the codes for my needs, hence the long code.

    cubangt: I tried uncommenting the line and still got the error. But, thanks for helping sir, I appreciate your effort.

    I added reputation to both of you for helping me out

+ 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. run time Error "1004" application defined or object defined error
    By farrag in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-06-2017, 10:30 AM
  2. Replies: 4
    Last Post: 11-13-2015, 09:03 PM
  3. Replies: 5
    Last Post: 08-19-2015, 07:10 PM
  4. [SOLVED] Run time error:1004 "Application defined or Object defined error"
    By mvneema in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-07-2014, 09:47 AM
  5. [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
  6. Error When Implementing Code: "1004 - Application-defined or object-defined error"
    By blueblazingdemon in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-10-2013, 11:21 AM
  7. Replies: 1
    Last Post: 05-06-2013, 06:07 AM

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