+ Reply to Thread
Results 1 to 9 of 9

From column A and column B data into 1 line pair

Hybrid View

vutienhp From column A and column B... 01-31-2015, 09:27 AM
MickG Re: From column A and column... 01-31-2015, 09:35 AM
vutienhp Re: From column A and column... 01-31-2015, 09:49 AM
Richard Buttrey Re: From column A and column... 01-31-2015, 09:35 AM
vutienhp Re: From column A and column... 01-31-2015, 10:00 AM
Richard Buttrey Re: From column A and column... 01-31-2015, 10:32 AM
MickG Re: From column A and column... 01-31-2015, 10:57 AM
  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    VietNam
    MS-Off Ver
    Excel 2003
    Posts
    46

    From column A and column B data into 1 line pair

    Hello all!
    I need a VBA Code to solve my problem as attachments.
    Please see the file.
    thank you!

    Note: If Column B has a value of 0 is not paired
    Attached Files Attached Files

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: From column A and column B data into 1 line pair

    Try:-
    Sub MG31Jan46
    Dim Rng As Range, Dn As Range, Stg As String
    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Not Dn.Offset(, 1) = 0 Then
            Stg = Stg & Dn.Value & ":" & Dn.Offset(, 1).Value & "Kg" & ", "
        End If
    Next Dn
    Range("I1").Value = Stg
    End Sub
    Regards Mick

  3. #3
    Registered User
    Join Date
    01-29-2013
    Location
    VietNam
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: From column A and column B data into 1 line pair

    Quote Originally Posted by MickG View Post
    Try:-
    Sub MG31Jan46
    Dim Rng As Range, Dn As Range, Stg As String
    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Not Dn.Offset(, 1) = 0 Then
            Stg = Stg & Dn.Value & ":" & Dn.Offset(, 1).Value & "Kg" & ", "
        End If
    Next Dn
    Range("I1").Value = Stg
    End Sub
    Regards Mick
    Your answer so fast!
    I want to ask you is that I want to delete the character "," at the end of the line you just created, then how?
    thank you!

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: From column A and column B data into 1 line pair

    Hi,

    Enter this to C2, and copy it down. Then select C16, copy it and paste it back as a value.

    Formula: copy to clipboard
    =C1&A2&":"&B2&"kg"
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    01-29-2013
    Location
    VietNam
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: From column A and column B data into 1 line pair

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Enter this to C2, and copy it down. Then select C16, copy it and paste it back as a value.

    Formula: copy to clipboard
    =C1&A2&":"&B2&"kg"
    Thank you!
    This may seem a long way, further still appear 0kg value in line pairing?

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: From column A and column B data into 1 line pair

    Hi,

    To avoid the zero use this modified formula in C2 copied down.

    Formula: copy to clipboard
    =H1&A2&":"&IF(B2=0,"",B2)&"kg, "

  7. #7
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: From column A and column B data into 1 line pair

    Try this:-
    Sub MG31Jan15
    Dim Rng As Range, Dn As Range, Stg As String
    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Not Dn.Offset(, 1) = 0 Then
            Stg = Stg & ", " & Dn.Value & ":" & Dn.Offset(, 1).Value & "Kg"
        End If
    Next Dn
    Range("I1").Value = Mid(Stg, 3)
    End Sub
    Regards Mick

  8. #8
    Registered User
    Join Date
    01-29-2013
    Location
    VietNam
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: From column A and column B data into 1 line pair

    Quote Originally Posted by MickG View Post
    Try this:-
    Sub MG31Jan15
    Dim Rng As Range, Dn As Range, Stg As String
    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Not Dn.Offset(, 1) = 0 Then
            Stg = Stg & ", " & Dn.Value & ":" & Dn.Offset(, 1).Value & "Kg"
        End If
    Next Dn
    Range("I1").Value = Mid(Stg, 3)
    End Sub
    Regards Mick
    Standard!
    thank you very much

+ 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. pair up data from consecutive cells in a column
    By seafarer in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-22-2008, 02:55 AM
  2. [SOLVED] pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 02:05 AM
  3. pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-05-2005, 11:05 PM
  4. pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-05-2005, 10:05 PM
  5. pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-01-2005, 06:05 AM

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