+ Reply to Thread
Results 1 to 8 of 8

Run Time Error

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2012
    Location
    Winnipeg, Manitoba
    MS-Off Ver
    Excel 2007
    Posts
    22

    Run Time Error

    Hello everyone,

    I have attached an excel workbook entitled the Data. I have a userform and have created command buttons on worksheet titled “Search” that run a macro to search based on different search criteria.
    The problem I am having is the first 5 command buttons work fine but the last 4 command buttons don’t function properly. When the command button is clicked and a selection is made from a drop down list, a Run Time Error ‘1004’ message pops up.

    Can anyone tell me where the error is? Thank you in advance.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Run Time Error

    At a quick glance, you haven't defined the variable "uRows" anywhere in any of the code. I got the error when I clicked on the first button, and I didn't bother testing anything after that.

    Also, you need to change your code from (in every instance):
    uRows = Sheets("Master").Range("B100000").End(xlUp).Row
    to
    uRows = Sheets("Master").Cells(Sheets("Master").Rows.Count, "B").End(xlUp).Row
    It might be a bit tidier if you use a
    With Sheets("Master")
        
    End With
    statement also...
    Last edited by ajryan88; 08-12-2013 at 08:09 PM.

  3. #3
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Run Time Error

    try attached, to see if you get the same error.
    Attached Files Attached Files

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Run Time Error

    Hi,

    It looks like it was created in XL 2003 which only has 65536 rows. You have references to row 100,000 before some .End(xlup) instructions so that will fail. Always use code like Range("A" & Rows.Count).End(xlup).

    Neither is uRows dimensioned as a Long Variable.

    In addition the sheet names you're adding use the Variable X which is not a string variable. Furthermore when this is converted to a string it contain the disallowable character : so this will need to be removed. Hence the line of code you need to use is:

    Sheets.Add.Name = Replace(CStr(X), ":", "")
    Last edited by Richard Buttrey; 08-12-2013 at 08:19 PM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,962

    Re: Run Time Error

    I tried debugging your code and got many errors due to missing or mis-placed "End Sub"'s and undefined variables
    Ben Van Johnson

  6. #6
    Registered User
    Join Date
    09-27-2012
    Location
    Winnipeg, Manitoba
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Run Time Error

    I have made some of the suggested changes that some of you that suggested. It certainly helped but now I am getting a Run Time Error '9' message and when I click debug the following line is highlighted:

    Rows(1).Copy Sheets(X).Range("A" & Rows.Count).End(3)(2)

    I have created and use Excel 2007. Thanks once again for taking the time to respond with your much appreciated suggestions.


    Private Sub cmdSubmit_Click()
    
    Dim d As String
    Dim X As String
    Dim i As Long
    Dim y As Long
    Range("AA1").Value = cboTheClassD
    cboTheClassD = Empty
    frmTheClassDEntry.Hide
    
    X = cboTheClassDName
    
    Sheets.Add.Name = Replace(CStr(X), ":", " ")
    
    Sheets("Master").Activate
    
    d = Range("AA1").Value
    
    i = 1
        Do Until ActiveCell.Value = d
        Cells(1, i).Select
                    
    i = i + 1
    Loop
    
    Rows(1).Copy Sheets(X).Range("A" & Rows.Count).End(3)(2)
    Sheets(X).Range("A1").EntireRow.Delete shift:=xlUp
    
    Sheets("Master").Activate
    
    For y = 2 To 100000
        If Cells(y, ActiveCell.Column) = X Then
            Cells(y, ActiveCell.Column).EntireRow.Copy Sheets(X).Range("A" & Rows.Count).End(3)(2)
        End If
        
    Next y
    
    Sheets(X).Activate
    Cells.Select
    Selection.Copy
    Cells.Select
    Selection.PasteSpecial Paste:=xlPasteValues
        Do Until Cells(1, 1) <> ""
            Cells(1, 1).Select
            Cells(1, 1).EntireColumn.Delete shift:=xlToRight
       Loop
        i = 1
        For i = 1 To Worksheets.Count
            Worksheets(i).Tab.ColorIndex = i + 10
            
        Next
        End Sub

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Run Time Error

    Hi,

    Probably because you are still using the Sheets(X) syntax.

    Remember we had to change this in the line that added the new sheet since X is not a string variabe. So wherever you have Sheets(X) substitute

    Replace(CStr(X), ":", " ")

  8. #8
    Registered User
    Join Date
    09-27-2012
    Location
    Winnipeg, Manitoba
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Run Time Error

    Hi Richard,

    Thank you so much for your input and suggestions. It finally works like I wanted it to work. Actually I had to replace the "X" in Sheets(X) with Replace(CStr(X),":"," ")

+ 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: 7
    Last Post: 05-15-2013, 09:02 AM
  2. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  3. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  4. Excel Macro Error - Run time error 1004 - Paste method of worksheet class failed
    By kvflynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2012, 10:51 AM
  5. [SOLVED] run-time error '1004': Application-defined or object-deifined error
    By rich5665@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2005, 05:05 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