2017-03-07 150 views
0

我有以下值工作表上創建Excel工作表 enter image description here 我想,用一個公式如果可能的話,重新排列這些值分爲三列,在另一個工作表中,根據它們是否是低,中上或高風險,像這樣通過過濾另一個工作表

enter image description here

不注意着色和邊界,我可以添加後(或使用條件格式)。

問題:有人可以提供一個最小工作示例(MWE)或使用公式將一個錶轉換爲三個並排表。

回答

1

我會用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 
相關問題