[英]swapped rows vba code in excel
I'm trying to generate combinations id_users in excel that they have a relation..so I used this sample code to gave me this result: 我试图在excel中生成具有关系的id_users组合。.所以我使用以下示例代码给了我这个结果:
the input is a pivot table : 输入是数据透视表:
' id_row id_users
10 1
2
3
66 4
11
this is my output 这是我的输出
'source target label
1 2 10
1 3 10
2 3 10
4 11 66
But it gave me this result : 但这给了我这个结果:
'source target label
1 2 10
1 3 10
2 1 10
2 3 10
3 1 10
3 2 10
4 11 66
11 4 66
as u see i didn't want to show the swapped rows too it's okay if it show duplicate row..but i don't want to show the swapped data..like : 1 2 and 2 1 it doesn't mean anything just a repeated info like : a with b has a relation and then u saw that b with a has a relation ..and it's just a repeated of an info that first i have it... in my code is it's show the data array sq user_1 that not equal with the data in sqq user_2 , but also I want to show the data that are not called in pervious sq user_1 : 如你所见,我也不想显示交换的行,如果它显示重复的行也可以..但是我不想显示交换的数据..如:1 2和2 1这并不意味着什么重复的信息,例如:a与b具有关系,然后您看到b与a具有关系..并且它只是信息的重复,首先我拥有它...在我的代码中是显示数据数组sq user_1与sqq user_2中的数据不相等,但我也想显示以前的sq user_1中未调用的数据:
'
'get the combinationsin the pivot table for this topic
sq = Range(rTopic, rTopic.End(xlDown).Offset(-1)).Offset(, 1).Resize(, 2).SpecialCells(2, 1).Value
'get the unique combinations of persons
sUniq = " "
For lUser_2 = 1 To UBound(sq, 1)
If InStr(sUniq, " " & sq(lUser_2, 2) & " ") = 0 Then
sUniq = sUniq & sq(lUser_2, 2) & " "
End If
Next
sqq = Split(Trim(sUniq))
'loop over user id's and generate combinations
For lUser_1 = 1 To UBound(sq, 1)
For lUser_2 = 0 To UBound(sqq)
If sq(lUser_1, 2) & "" <> sqq(lUser_2) Then
'we found a new combination, output to screen
Range(sStartingCellOutput).Offset(lRowOffset, lColOffset).Resize(1, 3).Value = Array(sq(lUser_1, 2), sqq(lUser_2), rTopic.Value)
'increment the counter
lRowOffset = lRowOffset + 1
If lRowOffset >= Rows.count Then
lRowOffset = 0
lColOffset = lColOffset + 4
End If
End If
Next
Next
I editted it to explain more in my code..just plz i need a samll help ? 我对其进行了编辑以解释代码中的更多内容。.请问我需要帮助吗? if my Q is not clear just comment for me...thanks
如果我的Q不清楚,请为我评论...谢谢
您需要在要检查的值上添加另一个空格
If InStr(sUniq, " " & sq(lUser_2, 2) & " ") = 0 Then
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.