+ Reply to Thread
Results 1 to 17 of 17

error 1004

Hybrid View

  1. #1
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    error 1004

    hi, ive got a 1004 problem on below yellow line, whats wrong with this ?


    Sub SplitCells()
    Dim i As Long
    With Application
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    Sheets("DATA1").Range("B" & Col).Select
    For i = 1 To Selection.Rows.Count
    Dim splitValues As Variant
    splitValues = Split(Selection.Rows(i).Value, ",")
    Selection.Rows(i).Resize(UBound(splitValues) - LBound(splitValues) + 1).Value = Application.Transpose(splitValues)
    Next i
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
    End With
    End Sub
    thanks
    Last edited by hamex; 09-09-2010 at 01:24 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error 1004

    Col is not initialized.

    Please change your QUOTE tags to CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: error 1004

    You are using a variable Col for the row, and you have not given that variable a value yet.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: error 1004

    as my first message in my forums and breaking the forum rules i need to say , ive download the xls file from this address : http://www.excelforum.com/excel-prog...s-to-rows.html and got this error . im really sorry for inconvience but im in hurry ,... can you help me ?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error 1004

    What are you trying to do?

  6. #6
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: error 1004

    thank you for reply , i need to split the separated-comma rows (text to rows) but that gives me "Application defined or object defined error". you can see the attachment ..

    thanks again
    Attached Files Attached Files

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error 1004

    Split them to appear where?

  8. #8
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: error 1004

    in new sheet named "DATA1" , i was download this file from john's post at "http://www.excelforum.com/excel-prog...s-to-rows.html" and modify the target content and after that on line 100 of my previous post's attachment give me the error.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error 1004

    Please make this simple and post a partial example of the output as you wish it to appear.

  10. #10
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: error 1004

    No offense, can you download my attach file to see the exact problem ?

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error 1004

    Try replaxcing all that code with this and see if it does what you want.
    Option Explicit
    
    Sub x()
        Dim iRow        As Long
        Dim asBuf()     As String
    
        Worksheets("Data").Copy After:=Sheets(Sheets.Count)
        ActiveSheet.Name = "DATA1"
    
        For iRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
            With Cells(iRow, "A")
                If InStr(.Text, ",") Then
                    asBuf = Split(Replace(.Text, " ", ""), ",")
                    .Offset(1).Resize(UBound(asBuf)).EntireRow.Insert
                    With .Resize(UBound(asBuf) + 1)
                        .Value = WorksheetFunction.Transpose(asBuf)
                        .Offset(, 1).Value = Cells(iRow, "B").Value
                    End With
                End If
            End With
        Next iRow
        
        With ActiveSheet.UsedRange
            .Value = .Value
            .EntireColumn.AutoFit
        End With
    End Sub
    Last edited by shg; 09-09-2010 at 02:26 PM.

  12. #12
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: error 1004

    thanks shg for your time, but this one not helping me and actually i need to solve the problem not change the whole program .

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: error 1004

    I see the Col variable is Public in another module. Perhaps if you move the macro into that module you'll get the stored value of Col.

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: error 1004

    Hi Hamex

    I believe you'll find your error in this line of code
    Col = Right(iCell.Offset(-lRows, 0).Address, 2)
    is due to the fact that once your row number exceeds 99, the formula in the offending line of code evaluates to 0 (zero).

    Change that line of code to
    Col = iCell.Offset(-lRows, 0).Row
    and you should be good to go.

    John

    PS: By the way, I tested Shg's code...it's much simpler than the code I wrote and it works wonderfully well.
    Last edited by jaslake; 09-10-2010 at 04:53 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  15. #15
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: error 1004

    john thank you very much for your kindly help , its ok now and the prob is solved .. God bless you

  16. #16
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: error 1004

    Why not using Excel's builtin facilities ?
    If the selection is restricted to cells in column B:

    Sub tst()
        Selection.TextToColumns , 1, -4142, , False, False, True, False, False
    End Sub



  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: error 1004

    Hi hamex

    You're welcome. Thanks for the blessings.

    John

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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