带VBA的笛卡尔积
如何在下面的代码中添加第三个和第四个范围/数组带VBA的笛卡尔积,vba,product,cartesian,Vba,Product,Cartesian,如何在下面的代码中添加第三个和第四个范围/数组 Sub cartesianproduct() Dim startrange As Range range1 = Application.InputBox(Prompt:="Please Select First Range", Type:=8) range2 = Application.InputBox(Prompt:="Please Select Second Range", Type:=8) Set startrange = Applic
Sub cartesianproduct()
Dim startrange As Range
range1 = Application.InputBox(Prompt:="Please Select First Range", Type:=8)
range2 = Application.InputBox(Prompt:="Please Select Second Range", Type:=8)
Set startrange = Application.InputBox(Prompt:="Please select where you want to put it", Type:=8)
array1 = [range1]
array2 = [range2]
startrange.Select
For i = 1 To UBound(array1)
For x = 1 To UBound(array2)
z = z + 1
ActiveCell.Offset(z, 0).Value = array1(i, 1)
ActiveCell.Offset(z, 1).Value = array2(x, 1)
Next
Next
End Sub
我需要添加range3、range4和array1、array2,但不确定在startrange下要做什么。选择…虽然此代码可能会回答问题,但提供有关如何以及为什么解决问题的其他上下文将提高答案的长期价值。
Sub cartesianproduct()
Dim startrange As Range
range1 = Application.InputBox(Prompt:="Please Select First Range", Type:=8)
range2 = Application.InputBox(Prompt:="Please Select Second Range", Type:=8)
range3 = Application.InputBox(Prompt:="Please Select Third Range", Type:=8)
Set startrange = Application.InputBox(Prompt:="Please select where you want to put it", Type:=8)
array1 = [range1]
array2 = [range2]
array3 = [range3]
startrange.Select
For i = 1 To UBound(array1)
For x = 1 To UBound(array2)
For y = 1 To UBound(array3)
Z = Z + 1
ActiveCell.Offset(Z, 0).Value = array1(i, 1)
ActiveCell.Offset(Z, 1).Value = array2(x, 1)
ActiveCell.Offset(Z, 2).Value = array3(y, 1)
Next
Next
Next
End Sub