Results 1 to 7 of 7

Thread: [RESOLVED] [Excel] split rows down macro

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Resolved [RESOLVED] [Excel] split rows down macro

    Hi All

    am new to VBA but have been using vb6 for the past few months
    I am trying to modify the code in this thread to work on my spread sheet.

    the sample spreadsheet that came with the code from that thread worked ok with the code.
    Thing is if a cell has only one value in it the macro stops seperating out any further multiple value rows (on the sample sheet)

    on my sheet I have accounted for this by testing the boundaries of the split array, but another problem then is it seems to only do the first row then stops splitting them altogether, although it does step down through the rest of the rows

    Ultimatly I want to be able to customize this so it works by selected column on a current work sheet, instead of the column being coded.

    a sample of my spreadsheet is attached including the current code I am working with.
    Attached Files Attached Files
    Thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel] split rows down macro

    the only cell in your sheet that meets the split criterior is in row 1
    C1 is the only cell that has a comma followed by a space
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: [Excel] split rows down macro

    Oh my god i am so asleep this morning. Thanks westconn.

    as i said I'm new to vba so would you have any suggestions on how to turn this from using column C1 to any selected col?

    was thinking something like this:
    vb Code:
    1. Set rngSource = ThisWorkbook.Worksheets(1).Range((ActiveCell.Column) & "1")

    but it gives an error so I think I've got the wrong idea
    Last edited by wolf99; Aug 8th, 2007 at 06:42 AM. Reason: add was thinking...
    Thanks

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel] split rows down macro

    vb Code:
    1. Set rngSource = ActiveCell.EntireColumn
    this works
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: [Excel] split rows down macro

    ah dont think I explained myself well, sorry am only learning this as i go along

    The code you gave selects the entire column of the column the active cell is in, yes?

    I need it that the first cell of the column of the column of the active cell is selected.

    ie
    If I select C5 as the active cell, then run the macro rngSource will then be given C1; or if I select D19 then D1 will be given to rngSource;
    thus having the same effect as hardcoding
    vb Code:
    1. Set rngSource = ThisWorkbook.Worksheets(1).Range("C1")

    so I need to get the column label and then add "1" (the row) to it to be a starting point for the macro.
    overall this means the user can select the column for the macro to act on by just selecting any cell in that column.

    Ta
    Thanks

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel] split rows down macro

    Set rngSource = Cells(1, ActiveCell.Column)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: [Excel] split rows down macro

    have it

    vb Code:
    1. Set rngSource = Cells(1, (ActiveCell.Column))

    does the job. thanks for all your help westconn1

    edit: hey posted at the same time; you know what they say about great minds!
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width