通过过滤另一个工作表
问题描述:
我有以下值工作表上创建Excel工作表 我想,用一个公式如果可能的话,重新排列这些值分为三列,在另一个工作表中,根据它们是否是低,中上或高风险,像这样通过过滤另一个工作表
不注意着色和边界,我可以添加后(或使用条件格式)。
问题:有人可以提供一个最小工作示例(MWE)或使用公式将一个表转换为三个并排表。
答
我会用VBA来解决这个问题:
Sub Sortdata()
Dim wsRisk As Worksheet, wsThisSheet As Worksheet
Dim colHigh As Long, colMed As Long, ColLow As Long
colHigh = 3
colMed = 3
ColLow = 3
Set wsThisSheet = ActiveSheet
With ThisWorkbook
.Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = "Risk"
End With
Set wsRisk = Worksheets("Risk")
wsRisk.Range("A1").Value = "Risk of Responsibility"
wsRisk.Range("A2").Value = "High Risk"
wsRisk.Range("C2").Value = "Medium Risk"
wsRisk.Range("E2").Value = "Low Risk"
lastrow = wsThisSheet.Cells(Rows.Count, "B").End(xlUp).Row
For x = 2 To lastrow
If wsThisSheet.Cells(x, 4).Value = "High" Then
wsRisk.Range("A" & colHigh & ":B" & colHigh).Value = wsThisSheet.Range("B" & x & ":C" & x).Value
colHigh = colHigh + 1
ElseIf wsThisSheet.Cells(x, 4).Value = "Med" Then
wsRisk.Range("C" & colMed & ":D" & colMed).Value = wsThisSheet.Range("B" & x & ":C" & x).Value
colMed = colMed + 1
ElseIf wsThisSheet.Cells(x, 4).Value = "Low" Then
wsRisk.Range("E" & ColLow & ":F" & ColLow).Value = wsThisSheet.Range("B" & x & ":C" & x).Value
ColLow = ColLow + 1
End If
Next x
End Sub