HI Friends,
I tried to create a VBA code to generate List of possible combinations. But when I execute for first time it was successful ( though i tried multiple times). But unfortunately it stopped working stating Error msg as "Wrong number of arguments or invalid property assignments" when I am selecting a range of cells. below is the code:
when i execute the code it stuck at range and showing the error as mentioned above.
i am attaching screen shot of error msg.
Sub consolidate()
Dim xDRg1, xDRg2, xDRg3, xDRg4, xDRg5 As range ( when i select Range ( in caps) it is automatically converting in to lower case)
Dim xRg As range
Dim xStr As String
Dim xFN1, xFN2, xFN3, xFN4, xFN5 As Integer
Dim xSV1, xSV2, xSV3, xSV4, xSV5 As String
Set xDRg1 = range("A2:A6") 'First column data
Set xDRg2 = range("B2:B6") 'Second column data
Set xDRg3 = range("C2:C6") 'Third column data
Set xDRg4 = range("D2:D6") 'Third column data
Set xDRg5 = range("E2:E6") 'Third column data
xStr = "-" 'Separator
Set xRg = range("G2") 'Output cell
For xFN1 = 1 To xDRg1.Count
xSV1 = xDRg1.Item(xFN1).Text
For xFN2 = 1 To xDRg2.Count
xSV2 = xDRg2.Item(xFN2).Text
For xFN3 = 1 To xDRg3.Count
xSV3 = xDRg3.Item(xFN3).Text
For xFN4 = 1 To xDRg4.Count
xSV4 = xDRg4.Item(xFN4).Text
For xFN5 = 1 To xDRg5.Count
xSV5 = xDRg5.Item(xFN5).Text
xRg.Value = xSV1 & xStr & xSV2 & xStr & xSV3 & xSV4 & xStr & xSV5 & xStr
Set xRg = xRg.Offset(1, 0)
Next
Next
Next
Next
Next
End Sub
I tried to create a VBA code to generate List of possible combinations. But when I execute for first time it was successful ( though i tried multiple times). But unfortunately it stopped working stating Error msg as "Wrong number of arguments or invalid property assignments" when I am selecting a range of cells. below is the code:
when i execute the code it stuck at range and showing the error as mentioned above.
i am attaching screen shot of error msg.
Sub consolidate()
Dim xDRg1, xDRg2, xDRg3, xDRg4, xDRg5 As range ( when i select Range ( in caps) it is automatically converting in to lower case)
Dim xRg As range
Dim xStr As String
Dim xFN1, xFN2, xFN3, xFN4, xFN5 As Integer
Dim xSV1, xSV2, xSV3, xSV4, xSV5 As String
Set xDRg1 = range("A2:A6") 'First column data
Set xDRg2 = range("B2:B6") 'Second column data
Set xDRg3 = range("C2:C6") 'Third column data
Set xDRg4 = range("D2:D6") 'Third column data
Set xDRg5 = range("E2:E6") 'Third column data
xStr = "-" 'Separator
Set xRg = range("G2") 'Output cell
For xFN1 = 1 To xDRg1.Count
xSV1 = xDRg1.Item(xFN1).Text
For xFN2 = 1 To xDRg2.Count
xSV2 = xDRg2.Item(xFN2).Text
For xFN3 = 1 To xDRg3.Count
xSV3 = xDRg3.Item(xFN3).Text
For xFN4 = 1 To xDRg4.Count
xSV4 = xDRg4.Item(xFN4).Text
For xFN5 = 1 To xDRg5.Count
xSV5 = xDRg5.Item(xFN5).Text
xRg.Value = xSV1 & xStr & xSV2 & xStr & xSV3 & xSV4 & xStr & xSV5 & xStr
Set xRg = xRg.Offset(1, 0)
Next
Next
Next
Next
Next
End Sub