比如一个EXCLE文档,有A,B,C,D,E5列
现在要求生成一个新的文档,判断A,B,C的值相同时
在新生成的文档中以A,B,C,D,E,D,E,D,E。。的格式把A,B,C相同的D,E的值在同一列穷举
同事生成一个TOTAL列,求E列值得和
跪求VBA代码
VBA高级筛选 条件
答案:1 悬赏:20 手机版
解决时间 2021-02-27 05:55
- 提问者网友:皆是孤独
- 2021-02-26 22:16
最佳答案
- 五星知识达人网友:掌灯师
- 2021-02-26 23:56
说实在的,还真没怎么看明白你要求的输出格式。
给你一段VBA代码,你试下效果,再参照着进行修改吧。
这段代码,要在“源数据”所在的工作簿运行。
Private Sub DataProc()
Dim objWbNew As Workbook
Dim objShNew As Worksheet
Dim objShSrc As Worksheet
Dim vA&, vB&, vC&, vD&, vE&
Dim i&, R&, strTmp$
Set objShSrc = Sheets("Sheet1") '数据在Sheet1表
Set objWbNew = Workbooks.Add
Set objShNew = objWbNew.Sheets(1)
i = 1 '如果有表头行,数据从第几行开始,就等于几
R = i
Do
strTmp = objShSrc.Cells(i, 1)
If (Len(strTmp) = 0) Then Exit Do
vA = strTmp
vB = objShSrc.Cells(i, 2)
vC = objShSrc.Cells(i, 3)
If ((vA = vB) And (vB = vC)) Then
'A,B,C,D,E,D,E,D,E
vD = objShSrc.Cells(i, 4)
vE = objShSrc.Cells(i, 5)
objShNew.Cells(R, 1) = vA
objShNew.Cells(R, 2) = vB
objShNew.Cells(R, 3) = vC
objShNew.Cells(R, 4) = vD
objShNew.Cells(R, 5) = vE
objShNew.Cells(R, 6) = vD
objShNew.Cells(R, 7) = vE
objShNew.Cells(R, 8) = vD
objShNew.Cells(R, 9) = vE
R = R + 1
End If
i = i + 1
Loop
End Sub
给你一段VBA代码,你试下效果,再参照着进行修改吧。
这段代码,要在“源数据”所在的工作簿运行。
Private Sub DataProc()
Dim objWbNew As Workbook
Dim objShNew As Worksheet
Dim objShSrc As Worksheet
Dim vA&, vB&, vC&, vD&, vE&
Dim i&, R&, strTmp$
Set objShSrc = Sheets("Sheet1") '数据在Sheet1表
Set objWbNew = Workbooks.Add
Set objShNew = objWbNew.Sheets(1)
i = 1 '如果有表头行,数据从第几行开始,就等于几
R = i
Do
strTmp = objShSrc.Cells(i, 1)
If (Len(strTmp) = 0) Then Exit Do
vA = strTmp
vB = objShSrc.Cells(i, 2)
vC = objShSrc.Cells(i, 3)
If ((vA = vB) And (vB = vC)) Then
'A,B,C,D,E,D,E,D,E
vD = objShSrc.Cells(i, 4)
vE = objShSrc.Cells(i, 5)
objShNew.Cells(R, 1) = vA
objShNew.Cells(R, 2) = vB
objShNew.Cells(R, 3) = vC
objShNew.Cells(R, 4) = vD
objShNew.Cells(R, 5) = vE
objShNew.Cells(R, 6) = vD
objShNew.Cells(R, 7) = vE
objShNew.Cells(R, 8) = vD
objShNew.Cells(R, 9) = vE
R = R + 1
End If
i = i + 1
Loop
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯