EXCEL如何返回某列中等于某个数值的数所对应的信息
问题提得不准确,请看以下描述:表格中有A列,B列;B列有很多的数值(有很多值相等);如果B列中等于某个数值(X),则返回对应的A列中的值,B列中有多少个X就返回多少个对应...
问题提得不准确,请看以下描述:
表格中有A列,B列;B列有很多的数值(有很多值相等);如果B列中等于某个数值(X),则返回对应的A列中的值,B列中有多少个X就返回多少个对应的A列的数据,中间用“,”隔开。
如果能够帮助到我,还会继续给分,谢谢!
一般情况,我所做的表格B列都只有3个不同的值,我就需要统计出B列的不通值对应的A列中的数据,中间需要用“,”隔开。 展开
表格中有A列,B列;B列有很多的数值(有很多值相等);如果B列中等于某个数值(X),则返回对应的A列中的值,B列中有多少个X就返回多少个对应的A列的数据,中间用“,”隔开。
如果能够帮助到我,还会继续给分,谢谢!
一般情况,我所做的表格B列都只有3个不同的值,我就需要统计出B列的不通值对应的A列中的数据,中间需要用“,”隔开。 展开
6个回答
展开全部
我也来一段通用的,数据可以增减,代码不影响,楼上代码受限哦
Sub 统计()
Dim arr, arr1()
Dim R&, x&, y&,i&
Set d = CreateObject("scripting.dictionary")
R = Range("A65536").End(xlUp).Row
ReDim arr(1 To R, 1 To 2)
arr = Range("A1:B" & R).Value
For x = 1 To UBound(arr)
If Not d.exists(arr(x, 2)) Then
y = y + 1
d.Add arr(x, 2), ""
ReDim Preserve arr1(1 To y)
For i = 1 To UBound(arr)
If arr(i, 2) = arr(x, 2) Then
arr1(y) = arr1(y) & arr(i, 1) & ","
End If
Next i
arr1(y) = "第" & Left(arr1(y), Len(arr1(y)) - 1) & "的值为" & arr(x, 2)
End If
Next x
Range("C1").Resize(UBound(arr1), 1) = Application.Transpose(arr1)
End Sub
不明白,直接HI我,给你讲解清楚
根据您的文件需求修改代码如下
Sub 统计()
Dim arr, arr1()
Dim R&, x&, y&, i&
Set d = CreateObject("scripting.dictionary")
R = Range("A65536").End(xlUp).Row
ReDim arr(1 To R, 1 To 8)
arr = Range("A2:H" & R).Value
For x = 1 To UBound(arr)
If Not d.exists(arr(x, 8)) Then
d.Add arr(x, 8), ""
For i = 1 To UBound(arr)
If arr(i, 8) = arr(x, 8) Then
t = t & arr(i, 1) & ","
End If
Next i
t1 = t1 & "第" & Left(t, Len(t) - 1) & "的值为" & arr(x, 8) & ";"
t = ""
End If
Next x
Range("L2") = t1
End Sub
Sub 统计()
Dim arr, arr1()
Dim R&, x&, y&,i&
Set d = CreateObject("scripting.dictionary")
R = Range("A65536").End(xlUp).Row
ReDim arr(1 To R, 1 To 2)
arr = Range("A1:B" & R).Value
For x = 1 To UBound(arr)
If Not d.exists(arr(x, 2)) Then
y = y + 1
d.Add arr(x, 2), ""
ReDim Preserve arr1(1 To y)
For i = 1 To UBound(arr)
If arr(i, 2) = arr(x, 2) Then
arr1(y) = arr1(y) & arr(i, 1) & ","
End If
Next i
arr1(y) = "第" & Left(arr1(y), Len(arr1(y)) - 1) & "的值为" & arr(x, 2)
End If
Next x
Range("C1").Resize(UBound(arr1), 1) = Application.Transpose(arr1)
End Sub
不明白,直接HI我,给你讲解清楚
根据您的文件需求修改代码如下
Sub 统计()
Dim arr, arr1()
Dim R&, x&, y&, i&
Set d = CreateObject("scripting.dictionary")
R = Range("A65536").End(xlUp).Row
ReDim arr(1 To R, 1 To 8)
arr = Range("A2:H" & R).Value
For x = 1 To UBound(arr)
If Not d.exists(arr(x, 8)) Then
d.Add arr(x, 8), ""
For i = 1 To UBound(arr)
If arr(i, 8) = arr(x, 8) Then
t = t & arr(i, 1) & ","
End If
Next i
t1 = t1 & "第" & Left(t, Len(t) - 1) & "的值为" & arr(x, 8) & ";"
t = ""
End If
Next x
Range("L2") = t1
End Sub
展开全部
在C1输入X
在D1输入公式
=INDEX(A:A,SMALL(IF(B$1:B$100=C$1,ROW($1:$100),4^8),ROW()))&""
数组公式请以ctrl+shift+enter三键组合结束输入.
把D1往下拉直至出现空白即可
这样你要的答案在D1中排列好了
如果你一定要用","来隔开的话,估计只能请高手些VBA了
在D1输入公式
=INDEX(A:A,SMALL(IF(B$1:B$100=C$1,ROW($1:$100),4^8),ROW()))&""
数组公式请以ctrl+shift+enter三键组合结束输入.
把D1往下拉直至出现空白即可
这样你要的答案在D1中排列好了
如果你一定要用","来隔开的话,估计只能请高手些VBA了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
按Alt+F8创建任意一个宏,然后将下列代码替换代码窗口的所有内容,关闭后,在EXCEL按Alt+F8运行宏“统计”即可:
Sub 统计()
Dim i, a As Integer
Dim pp(), qq()
pp = Array("统计结果是: ", "第", "第", "第")
qq = Array("", "的值是100", "的值是200", "的值是300")
a = Sheet1.UsedRange.Rows.Count
For i = 1 To a
Select Case Cells(i, 2)
Case 100
pp(1) = pp(1) & Cells(i, 1) & ","
Case 200
pp(2) = pp(2) & Cells(i, 1) & ","
Case 300
pp(3) = pp(3) & Cells(i, 1) & ","
End Select
Next i
For i = 0 To 3
Cells(i + 3, 3) = Left(pp(i), Len(pp(i)) - 1) & qq(i)
Next i
End Sub
Sub 统计()
Dim i, a As Integer
Dim pp(), qq()
pp = Array("统计结果是: ", "第", "第", "第")
qq = Array("", "的值是100", "的值是200", "的值是300")
a = Sheet1.UsedRange.Rows.Count
For i = 1 To a
Select Case Cells(i, 2)
Case 100
pp(1) = pp(1) & Cells(i, 1) & ","
Case 200
pp(2) = pp(2) & Cells(i, 1) & ","
Case 300
pp(3) = pp(3) & Cells(i, 1) & ","
End Select
Next i
For i = 0 To 3
Cells(i + 3, 3) = Left(pp(i), Len(pp(i)) - 1) & qq(i)
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ALT+F11打开VBA窗口,双击表1,粘贴如下代码,按F5运行。注意我采用的是1-20行数据,20可以更改更大的行数。
Sub shu()
a = Cells(1, 2)
For i = 2 To 20
If Cells(i, 2) <> a Then
b = Cells(i, 2)
bh = i
Exit For
End If
Next i
For j = 3 To 20
If Cells(j, 2) <> a And Cells(j, 2) <> b Then
c = Cells(j, 2)
ch = j
Exit For
End If
Next j
aRow = "第1"
For m = 2 To 20
If Cells(m, 2) = a Then
aRow = aRow & "," & m
End If
Next m
bRow = "第" & bh
For n = bh + 1 To 20
If Cells(n, 2) = b Then
bRow = bRow & "," & n
End If
Next n
cRow = "第" & ch
For k = ch + 1 To 20
If Cells(k, 2) = c Then
cRow = cRow & "," & k
End If
Next k
Cells(1, 3) = aRow & "的值为" & a
Cells(2, 3) = bRow & "的值为" & b
Cells(3, 3) = cRow & "的值为" & c
End Sub
Sub shu()
a = Cells(1, 2)
For i = 2 To 20
If Cells(i, 2) <> a Then
b = Cells(i, 2)
bh = i
Exit For
End If
Next i
For j = 3 To 20
If Cells(j, 2) <> a And Cells(j, 2) <> b Then
c = Cells(j, 2)
ch = j
Exit For
End If
Next j
aRow = "第1"
For m = 2 To 20
If Cells(m, 2) = a Then
aRow = aRow & "," & m
End If
Next m
bRow = "第" & bh
For n = bh + 1 To 20
If Cells(n, 2) = b Then
bRow = bRow & "," & n
End If
Next n
cRow = "第" & ch
For k = ch + 1 To 20
If Cells(k, 2) = c Then
cRow = cRow & "," & k
End If
Next k
Cells(1, 3) = aRow & "的值为" & a
Cells(2, 3) = bRow & "的值为" & b
Cells(3, 3) = cRow & "的值为" & c
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-02-06 · 知道合伙人软件行家
关注
展开全部
如果不会程序,用排序、筛选、if和&做一些操作也可以实现。
这么做主要靠的思路,而不是技术! 呵呵
这么做主要靠的思路,而不是技术! 呵呵
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我来试试,先报名,后拿分。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询