1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

MS Excel Question

Discussion in 'BBS Hangout' started by s land balla, Aug 27, 2009.

  1. s land balla

    s land balla Member

    Joined:
    Apr 24, 2001
    Messages:
    6,610
    Likes Received:
    365
    Haha, no wasn't my idea. We had to capture all of the various names related to specific documents...and this seemed like the best way to do it (at the time).
     
  2. Nice Rollin

    Nice Rollin Member

    Joined:
    Mar 30, 2006
    Messages:
    11,858
    Likes Received:
    321
    Has that stupid paperclip ever helped anybody?


    [​IMG]
     
  3. ScriboErgoSum

    ScriboErgoSum Member
    Supporting Member

    Joined:
    Aug 5, 2002
    Messages:
    3,149
    Likes Received:
    387
    Just reread the OP a little better. Here's a very quick macro that will take a target range and put them in a column that you specify. Just fill in the opening fields to fit your worksheet.

    Code:
    Sub ConcatenateNames()
        Dim ls_Worksheet As String
        Dim ls_SourceColumn As String
        Dim li_StartRow As Integer
        Dim li_EndRow As Integer
        Dim ls_TargetColumn As String
        Dim li_TargetRow As Integer
        Dim li_Index As Integer
        Dim lb_Continue As Boolean
        Dim li_Result As Integer
        Dim ls_Range As String
        Dim ls_TargetRange As String
        Dim ls_Temp As String
        Dim ls_Name As String
    
        '****************************************
        'Fill in these fields
        'The values below, take all names in Column B, rows 4-5
        'on the worksheet "Sheet1".  It will list the separate 
        'names in D5 in the same worksheet.    
        '****************************************
        ls_Worksheet = "Sheet1"
        ls_SourceColumn = "B"
        li_StartRow = 4
        li_EndRow = 5
        ls_TargetColumn = "D"
        li_TargetRow = 5
        
        li_Index = li_StartRow
        Do While (li_Index <= li_EndRow)
            lb_Continue = False
            ls_Range = ls_SourceColumn + CStr(li_Index)
            ls_Temp = Sheets(ls_Worksheet).Range(ls_Range).Value
     
            li_Result = InStr(1, ls_Temp, Chr(10))
            
            If (li_Result > 0) Then
                lb_Continue = True
            End If
            
            Do While (lb_Continue = True)
                ls_Name = Mid(ls_Temp, 1, li_Result - 1)
                ls_TargetRange = ls_TargetColumn + CStr(li_TargetRow)
                Sheets(ls_Worksheet).Range(ls_TargetRange).Value = ls_Name
                li_TargetRow = li_TargetRow + 1
                ls_Temp = Trim(Mid(ls_Temp, li_Result + 1, 500))
                
                li_Result = InStr(1, ls_Temp, Chr(10))
                If (li_Result > 0) Then
                    lb_Continue = True
                Else
                    lb_Continue = False
                End If
                
            Loop
        
            ls_TargetRange = ls_TargetColumn + CStr(li_TargetRow)
            Sheets(ls_Worksheet).Range(ls_TargetRange).Value = ls_Temp
            li_TargetRow = li_TargetRow + 1
        
            li_Index = li_Index + 1
        Loop
    End Sub
    
    EDIT: I should have stated that it will take a source column of mixed names (separated by ALT+ENTER or on their own).
     
    #23 ScriboErgoSum, Aug 27, 2009
    Last edited: Aug 27, 2009
    1 person likes this.
  4. s land balla

    s land balla Member

    Joined:
    Apr 24, 2001
    Messages:
    6,610
    Likes Received:
    365
    Thanks man, really appreciate it. I'll try it out later today.
     
  5. ScriboErgoSum

    ScriboErgoSum Member
    Supporting Member

    Joined:
    Aug 5, 2002
    Messages:
    3,149
    Likes Received:
    387
    No worries. Let me know if you have any problems running it.
     

Share This Page

  • About ClutchFans

    Since 1996, ClutchFans has been loud and proud covering the Houston Rockets, helping set an industry standard for team fan sites. The forums have been a home for Houston sports fans as well as basketball fanatics around the globe.

  • Support ClutchFans!

    If you find that ClutchFans is a valuable resource for you, please consider becoming a Supporting Member. Supporting Members can upload photos and attachments directly to their posts, customize their user title and more. Gold Supporters see zero ads!


    Upgrade Now