2017-05-16 166 views
0

所以我有一個公式,考慮其他單元格(L:L和K:K)中的其他兩個給定值來確定分數。現在它只適用於指定的引用單元格(L2,K2,M2),並且我試圖讓它適用於整列,而不是僅適用於一列。轉換單個單元格引用整個列參考Excel VBA

下面是VBA代碼:

Sub ExplicitScore() 
    If Range("L2").Value = "Healthcare" Then 
     Select Case Range("K2").Value 
     Case "Executive" 
      Range("M2").Value = 60 
     Case "IT", "Clinical", "Finance/Revenue Cycle", "Security/Risk/Compliance", "Patient Access/Records" 
      Range("M2").Value = 50 
     Case "HIM", "Patient Quality/Safety" 
      Range("M2").Value = 40 
     Case "Pharmacy", "Telecommunications", "Admin" 
      Range("M2").Value = 20 
     Case Else 
      Range("M2").Value = 10 
     End Select 
    Else 
     Select Case Range("K2").Value 
     Case "Executive", "IT" 
      Range("M2").Value = 10 
     Case Else 
      Range("M2").Value = 0 
     End Select 
    End If 

End Sub 
+0

你的意思是你希望它在L2,K2,M2的工作,然後第3行,然後第4行,等等,直到第一個空行(或其他一些預定義行) ? – BruceWayne

+0

Yessir!我已經給出了L2,L3 ... Ln中的值,並給出了K2,K3 ... Kn中的值,作爲每行的標準,其結果應該是M2,M3 ... Mn – Tyler

回答

0

一個偉大的解決辦法是建立一個功能,而不是一分。將您的標準設置爲變量。下面是轉換後的代碼:

Function ExScore(Industry, JobCategory) 
    If Industry = "Healthcare" Then 
     Select Case JobCategory 
     Case "Executive" 
      ExScore = 60 
     Case "IT", "Clinical", "Finance/Revenue Cycle", "Security/Risk/Compliance", "Patient Access/Records" 
      ExScore = 50 
     Case "HIM", "Patient Quality/Safety" 
      ExScore = 40 
     Case "Pharmacy", "Telecommunications", "Admin" 
      ExScore = 20 
     Case Else 
      ExScore = 10 
     End Select 
    Else 
     Select Case JobCategory 
     Case "Executive", "IT" 
      ExScore = 10 
     Case Else 
      ExScore = 0 
     End Select 
    End If 

End Function 
相關問題