Results 1 to 8 of 8

Thread: Can this be done? (Excel Macro Probably Needed)

Hybrid View

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Can this be done? (Excel Macro Probably Needed)

    Sorry, yes...each entry has it's own column and is in it's own cell.

    So column A would be "name" and then B,C,D,E etc may have codes, up to a maximum of probably 10.
    Last edited by The_Grudge; Mar 8th, 2006 at 08:29 AM.

  2. #2
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Can this be done? (Excel Macro Probably Needed)

    Try this:
    VB Code:
    1. Private Sub SplitRows()
    2.  
    3.     Dim oRange As Range, lRow As Long, lCol As Long, oOut As Worksheet, lOut As Long
    4.     Dim sValue As String, sName As String
    5.    
    6.     Set oRange = Application.ActiveSheet.UsedRange          'Get the range of used cells.
    7.     Set oOut = Application.ActiveWorkbook.Worksheets.Add    'Create an output worksheet.
    8.  
    9.     For lRow = 1 To oRange.Rows.Count                       'Loop through all rows.
    10.         sName = oRange.Cells(lRow, 1).Value                 'Get the name from column A.
    11.         sName = Trim$(sName)                                'Trim it.
    12.         If Len(sName) <> 0 Then                             'Check to see if there is an entry.
    13.             For lCol = 2 To oRange.Columns.Count            'Loop through the remaining columns.
    14.                 sValue = oRange.Cells(lRow, lCol).Value     'Get the value from that cell.
    15.                 sValue = Trim$(sValue)                      'Trim it.
    16.                 If Len(sValue) <> 0 Then                    'See if there is a value there.
    17.                     lOut = lOut + 1                         'Increment the output row counter.
    18.                     oOut.Cells(lOut, 1).Value = sName       'Write the name cell.
    19.                     oOut.Cells(lOut, 2).Value = sValue      'Write the value cell.
    20.                 End If
    21.             Next lCol
    22.         End If
    23.     Next lRow
    24.    
    25.     Set oRange = Nothing                                    'Release objects.
    26.     Set oOut = Nothing
    27.  
    28. End Sub

  3. #3

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Can this be done? (Excel Macro Probably Needed)

    That works really well with a little tweak here and there (cell range) so thanks!

    I just have one more question. If I have more columns across the top how do I copy them over as well.

    So (commas indicate columns)

    JOE SMITH, A303, A505, N858, 788 Beverly Hills Ave, Los Angeles

    Should Read....

    JOE SMITH, A303, 788 Beverly Hills Ave, Los Angeles
    JOE SMITH, A505, 788 Beverly Hills Ave, Los Angeles
    JOE SMITH, N858, 788 Beverly Hills Ave, Los Angeles

    You follow?

    Oh, the counter doesn't seem to print on the new page either...but I think I can tweak it.

  4. #4

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Can this be done? (Excel Macro Probably Needed)

    Nevermind, I got it.

    Thanks man, you saved my mouse hand A LOT of dickin' around LOL


  5. #5
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Can this be done? (Excel Macro Probably Needed)

    Just copy them out at the same time the name is copied. It looks like they will be in a fixed column or always in the last column. If it's fixed, it's really easy, just always write that cell the same place in the code that the name writes. If it's always in the last cell (but not always in the same column), it's a little trickier. You might scan all of the cell values into an array, and then use first element / last element in each row, and then loop through the middle of the array.

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