+ Reply to Thread
Results 1 to 7 of 7

Receiving Various Run Time Errors On A Simple Piece of Code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Receiving Various Run Time Errors On A Simple Piece of Code

    Morning folks,

    Could someone please review the attached sheet and elaborate on why i cant get it to work!

    All it needs to do is produce a list of unique values for the SUMIFS formula to populate costs on.

    Trying to use it as an alternative to a pivot table.

    pivottable alternative for autoloader.xlsm

    Cheers,

    HG

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Receiving Various Run Time Errors On A Simple Piece of Code

    HG,
    Part of the issue was that you didn't declare variables, like sRow, fRow etc. Also, use Option Explicit at the beginning of your code then "step" through your code and it will usually highlight the problem line(s) of code for you. It wont tell you specifically what's wrong with it, but at least you will know where the error is. to step through code, click any line in your code then press F8, this will go line by line through you code. Here is updated code for you...it may still error out on the ActiveSheet.Range...... line, but I'm not sure why yet..
    Option Explicit
    Sub test()
    
    Dim rFind As Object
    Dim fRow As Long
    Dim sRow As Long
    
        With Range("b4:b10000")
            Set rFind = .Find(What:="", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
            If Not rFind Is Nothing Then
                fRow = rFind.Row
            End If
        End With
        
            With Range("b1:b10000")
            Set rFind = .Find(What:="ID", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
            If Not rFind Is Nothing Then
                sRow = rFind.Row
                sRow = sRow + 1
            End If
        End With
    
    'Range(Cells(4, 2), (Cells(fRow, 4 )))
    
    ActiveSheet.Range(Cells(sRow, 2), (Cells(fRow, 4))).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ActiveSheet.Range(Cells(4, 4)), Unique:=True
    
        Range("E4:F2000").Select
        ActiveSheet.Range("$E$4:$F$28").RemoveDuplicates Columns:=Array(1, 2), Header _
            :=xlNo
            
            
            
    
            
    
            
    
    End Sub
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Receiving Various Run Time Errors On A Simple Piece of Code

    Yeah I understand all of the option explicit etc stuff, i was stepping through when i was getting an error on the Active.Sheet Range, which like you, i cant understand!

    VBA is great, but the errors are consistently a mystery to me.

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Receiving Various Run Time Errors On A Simple Piece of Code

    LOL, they are to me as well....although some of them I understand a little better than I used to.

  5. #5
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Receiving Various Run Time Errors On A Simple Piece of Code

    The dreaded 1001 is the worst one, just an unknown, none categorized error.

    I've had to re-write code around that error about 200 times!

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Receiving Various Run Time Errors On A Simple Piece of Code

    Luckily, I haven't seen that one to often....I don't think.
    I think I have narrowed it down to the Action part of the code. When I break it down and step through it, it highlights that word.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,983

    Re: Receiving Various Run Time Errors On A Simple Piece of Code

    Here is your runtime error BUT it won't solve your overall problem--you still have some issues. Remove the code in red.
    ActiveSheet.Range(Cells(sRow, 2), (Cells(fRow, 4))).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ActiveSheet.Range(Cells(4, 4)), Unique:=True
    The destination for your advanced filter copy overlaps with the source data. You are copying from column B:D and pasting to D. Also you are including the cost column in your copy, so nearly every row is unique anyway. Although I was able to do this manually in Excel with no error, it gave weird results and I have to wonder why you want to do that. Based on your formulas, I think it is an error.

    Let's take a step back and talk about what it is you want to do. You want a unique list to use SUMIF to calculate costs. Please look at the attached and see if that gets you there.

    To be clear, you see the result but I updated your macro and formulas so you should be able to wipe out columns F:G and run the macro again.
    Attached Files Attached Files
    Last edited by 6StringJazzer; 12-04-2015 at 01:06 PM. Reason: added blue text
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. receiving the 1004 error code.
    By starlev in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2015, 10:00 AM
  2. Run Time Errors - Code not working
    By sophia_1234 in forum Excel Programming / VBA / Macros
    Replies: 34
    Last Post: 09-24-2014, 11:28 AM
  3. [SOLVED] I can't figure out why I am receiving a run time error '91'?
    By redsab in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-11-2014, 05:29 PM
  4. First time coding in VB, no errors but my very simple script isn't working. Help?
    By metajellyfish in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-17-2012, 05:01 PM
  5. If or Matching Still Receiving Errors
    By GC29 in forum Excel General
    Replies: 6
    Last Post: 06-10-2010, 08:49 PM
  6. Running simple VBA code causing screen errors
    By RickCornelisse in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-01-2009, 10:53 AM
  7. No errors, but not receiving desired result
    By moike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2006, 04:18 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