Concatenate permutations between two columns

前端 未结 4 1634
陌清茗
陌清茗 2021-01-07 06:02

I need help with an excel assignment.

Name    City
---------------
John    London
Maxx    NY
Ashley  DC
        Paris

Solution for this mus

4条回答
  •  心在旅途
    2021-01-07 06:52

    This is a simple example in VBA. It is intended to show the concept, not the best practices. Please use it to get you started, and get back here if you need more help, if you want to improve the performances, etc.

    The example assumes that the two lists are in A1:An and B1:Bm, and the resulting list goes in column C.

    Sub Test()
      Dim R1 As Integer, R2 As Integer, R As Integer, NR As Integer
      NR = ActiveSheet.UsedRange.Rows.Count
      Columns(3).Clear
      For R1 = 1 To NR
        If Not IsEmpty(Cells(R1, 1)) Then
          For R2 = 1 To NR
            If Not IsEmpty(Cells(R2, 2)) Then
              R = R + 1
              Cells(R, 3) = Cells(R1, 1) & " - " & Cells(R2, 2)
            End If
          Next R2
        End If
      Next R1
    End Sub
    

提交回复
热议问题