+ Reply to Thread
Results 1 to 4 of 4

How to modify VB code?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    How to modify VB code?

    Good morning,
    i would realy appreciate your assistance to to change or modify vb code please.
    Sub Combo()
    Dim lCol As Long, lJJ As Long, lKK As Long, lRw As Long
    Dim vAry As Variant
    
    lRw = Cells(2, 1).End(xlDown).Row - 1
    lCol = Cells(1, 2).End(xlToRight).Column - 1
    ReDim vAry(1 To lCol, 1 To 1)
    With Range("B2").Resize(lRw, lCol)
        For lKK = 1 To lCol
            For lJJ = 1 To lRw
                If .Cells(lJJ, lKK) = "X" Then vAry(lKK, 1) = vAry(lKK, 1) & Cells(lJJ + 1, 1)
            Next lJJ
        Next lKK
    End With
    Cells(lRw + 3, 2).Resize(lCol, 1).Value = vAry
    End Sub
    Code result Expected Result
    12379 1,2,3,7,9
    12348 1,2,3,4,8
    12457 1,2,4,5,7
    12569 1,2,5,6,9
    12678 1,2,6,7,8
    13469 1,3,4,6,9
    13567 1,3,5,6,7
    13589 1,3,5,8,9
    14568 1,4,5,6,8
    14789 1,4,7,8,9
    23456 2,3,4,5,6
    23578 2,3,5,7,8
    23689 2,3,6,8,9
    24589 2,4,5,8,9
    24679 2,4,6,7,9
    34579 3,4,5,7,9
    34678 3,4,6,7,8
    56789 5,6,7,8,9
    thank you
    sem

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,668

    Re: How to modify VB code?

    When you are in Advanced reply, click on the paperclip to open the upload window.

    View Pic
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    01-21-2011
    Location
    London,UK
    MS-Off Ver
    Excel 2007
    Posts
    241

    Re: How to modify VB code?

    Hi protonLeah,
    thanks for your time,much appreciated.
    when i run the code i need the numbers to be separated by comma at the end result, like in my post #1.
    Thanks
    sem

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,997

    Re: How to modify VB code?

    One way:

    Sub combo2()
    
    Dim i As Long
    Dim lLR As Long
    lLR = Range("A" & Rows.Count).End(xlUp).Row
    Dim j As Long
    Dim sString As String
    
    For i = 2 To lLR
        sString = ""
        For j = 1 To Len(Range("A" & i))
            If j = 1 Then
                sString = Left(Range("A" & i), 1)
            Else
                sString = sString & "," & Mid(Range("A" & i), j, 1)
            End If
        Next 'j
        Range("B" & i) = sString
    Next 'i
    
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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