+ Reply to Thread
Results 1 to 13 of 13

Concatenate With Loop Through 2 Columns of Information

Hybrid View

  1. #1
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Concatenate With Loop Through 2 Columns of Information

    Hi Thanks for any help in advance.
    I have a list of names with blank cells in Column A cell 2.
    I want the programme to scroll through this column until it finds a name, when it does I want it to look in cell offset(1, 1), in this case B3 to see if there is a number. I want this number to be moved to offset (0, 1) AND any subsequent numbers below it until the next blank cell in that column (B).
    In the attached image cell B2 will contain all numbers in cells B3:B9 with a / between them. Cell B10 will have number from B11 and B12 will have B13:B15. If there is no number it will just continue to the next name in column A. My rough code below delivered the first number only in the relevant cell and I'm not clever enough to get it right. It does not have to be super slick as it's for one time use. Again thank you ;-)
    Sorry forgot to say I need numbers in column B cleared as they are concatenated into the single cell.

    Spreadsheet.jpg
    
    Sub Concatene()
    Dim rng As Long
    Dim r As Integer
    
      For r = 2 To 9440
     Cells(r, 1).Select
     If Selection <> "" Then If Selection.Offset(1, 1) <> 0 Then Selection.Offset(0, 1) = Selection.Offset(0, 1) & "/" & Selection.Offset(1, 1)
     
     Next
     
    End Sub
    Last edited by nigelld; 05-28-2014 at 06:54 AM.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate With Loop Through 2 Columns of Information

    Maybe:

    Sub nigelld()
    Dim rcell As Range
    For Each rcell In Range("A2:A" & Range("B" & Rows.count).End(3)(1).Row)
        If rcell.Value <> "" Then
            rcell.offset(1, 1).Cut rcell.offset(, 1)
        End If
    Next rcell
    End Sub

  3. #3
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Re: Concatenate With Loop Through 2 Columns of Information

    Hi John
    Thanks for that, but it only moves the first number up then scrolls through the remaining numbers, then after the next blank moves the first number again.
    Nigel ;-)

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate With Loop Through 2 Columns of Information

    Maybe:

    Sub nigelld()
    Dim i As Long
    For i = Range("B" & Rows.count).End(3)(1).Row To 2 Step -1
    
        If Range("A" & i).Value <> "" Then
            Range("A" & i).offset(1, 1).Cut Range("A" & i).offset(, 1)
            Rows(i + 1).Delete
        End If
    Next i
    End Sub

  5. #5
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Re: Concatenate With Loop Through 2 Columns of Information

    Although I'm eternally grateful for all help I can't get that bit of code to concatenate all the numbers, it just takes the first one and deletes it and I need all the numbers below the name, if any, and before the next blank cell adjacent to the next name to be in the adjacent cell to the name. Sorry ;-)

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate With Loop Through 2 Columns of Information

    Can you attach a file with some sample data. Preferably with a Sheet before the macro is run, and a Sheet with what you want it too look like after the macro is run. To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  7. #7
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Re: Concatenate With Loop Through 2 Columns of Information

    Thanks John cannot believe how quickly you do that ;-)

  8. #8
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Re: Concatenate With Loop Through 2 Columns of Information

    Thanks John I will do it as soon as I get back to my pc

    Sent from my HTC One using Tapatalk

  9. #9
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Re: Concatenate With Loop Through 2 Columns of Information

    Hi John
    I have attached the file. The blank rows I can get rid afterwards with a simple sort.
    Thank you
    Nigel
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate With Loop Through 2 Columns of Information

    Maybe:

    Sub nigelld()
    Dim i As Long
    Dim x As String
    x = ""
    For i = 2 To Range("B" & Rows.count).End(3)(1).Row
    
        If Range("A" & i).Value <> "" And Range("B" & i).Value = "" Then
            Range("B" & i + 1).Select
            If ActiveCell.Value <> "" And ActiveCell.offset(, -1) = "" Then
                Do Until ActiveCell.Value = ""
                x = x & "/" & ActiveCell.Value
                ActiveCell.offset(1).Select
                Loop
                Range("B" & i).Value = x
            Else: GoTo zz
            End If
        End If
    zz:
                    
    x = ""
    Next i
    For Each rcell In Range("B2:B" & Range("B" & Rows.count).End(3)(1).Row)
        If rcell.offset(, -1).Value = "" Then rcell.Value = ""
        If rcell.Value <> "" Then rcell.Value = Right(rcell, Len(rcell) - 1)
    Next rcell
    End Sub
    Last edited by JOHN H. DAVIS; 05-29-2014 at 07:48 AM.

  11. #11
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Re: Concatenate With Loop Through 2 Columns of Information

    Thank you very much John it worked perfectly BIG :-)

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate With Loop Through 2 Columns of Information

    You're welcome. Glad to help out and thanks for the feedback. Please comply with Forum Rule No 9.


    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

  13. #13
    Registered User
    Join Date
    05-22-2014
    Posts
    11

    Re: Concatenate With Loop Through 2 Columns of Information

    Will do

    Sent from my HTC One using Tapatalk

+ 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. Nested loop to concatenate 2 columns of data
    By JohnnyBGood in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2015, 07:42 AM
  2. Concatenate columns with information base on user selection
    By gward2701 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-05-2012, 09:55 PM
  3. [SOLVED] Return row 1 information if selected and concatenate
    By rmack1272 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-07-2012, 02:54 PM
  4. Replies: 0
    Last Post: 08-20-2012, 12:10 PM
  5. Replies: 8
    Last Post: 08-06-2012, 09:58 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