2016-08-02 2 views
0

셀 값을 나눌 매크로를 만들고 그 값이 7.5 이상이면 셀을 짙은 녹색으로 채우고 계속 색칠을 계속합니다. 후속 셀은 짙은 녹색으로, 예를 들어 2.25는 2 셀 짙은 녹색이고 .25 밝은 녹색입니다. 또한 색칠 할 셀의 색 내용이 회색 인 경우 색이없는 셀에 올 때까지 활성 셀을 계속 움직입니다.원래 셀 값을 기준으로 다른 음영으로 여러 셀에 색 지정

For Each y In rng 
    If Not IsEmpty(y) And y > 7.5 And y <> "" And IsNumeric(y) Then 'I am having trouble here 
    y.Select 
     With ActiveCell.Offset(0, i).Interior 
     .Pattern = xlSolid 
     .PatternColorIndex = xlAutomatic 
     .ThemeColor = xlThemeColorAccent3 
     .TintAndShade = -0.249977111117893 
     .PatternTintAndShade = 0 
    End With 

    col = y.Value/7.5 

    Count = Left(col, Len(col) - InStr(1, col, ".")) 

    For i = 1 To Count 

    Do While ActiveCell.Offset(0, i).TintAndShade = -0.149998474074526 
    i = i + 1: Count = Count + 1 
    Loop 

    ActiveCell.Offset(0, i).Select 
    With Selection.Interior 
     .Pattern = xlSolid 
     .PatternColorIndex = xlAutomatic 
     .ThemeColor = xlThemeColorAccent3 
     .TintAndShade = -0.249977111117893 
     .PatternTintAndShade = 0 
    End With 
    Next i 

    Count = Right(col, Len(col) - InStr(1, col, ".")) 

    If Count > 0 And Count < 25 Then 
    ActiveCell.TintAndShade = -4.99893185216834E-02 
    ElseIf Count > 26 And Count < 50 Then 
    ActiveCell.TintAndShade = 0.799981688894314 
    ElseIf Count > 75 And Count < 100 Then 
    ActiveCell.TintAndShade = 0.599993896298105 
    End If 
    Next y 

    End If 
Next y 

회색조 셀이 주말 인 작업량을 표시하기위한 매크로이므로 건너 뛰면됩니다.

+0

정확히 작동하지 않는 항목은 무엇입니까? – Jordan

+0

만약 IsEmpty가 아니라면 (y) y> 7.5 그리고 y <> ""그리고 IsNumeric (y) 그러면 y가 7.5보다 클 때 클릭하지 않을 것입니다. – Lowpar

+1

@Lowpar 어떻게 정의 되나요? 7.5보다 큰 숫자 값을 얻었습니까? 7.5로 표시되는 문자열이 아닌가? –

답변

2

코드 들여 쓰기를 할 때, 당신은 문제가있는 부분을 분리 할 때 End If없이 IfNext y너무 많은 하나

For Each y In rng 
    ' ****** you are not closing this If ***** 
    If Not IsEmpty(y) And y > 7.5 And y <> "" And IsNumeric(y) Then 'I am having trouble here 
     y.Select 
     With ActiveCell.Offset(0, i).Interior 
      .Pattern = xlSolid 
      .PatternColorIndex = xlAutomatic 
      .ThemeColor = xlThemeColorAccent3 
      .TintAndShade = -0.249977111117893 
      .PatternTintAndShade = 0 
     End With 

     col = y.Value/7.5 

     Count = Left(col, Len(col) - InStr(1, col, ".")) 

     For i = 1 To Count 

      Do While ActiveCell.Offset(0, i).TintAndShade = -0.149998474074526 
       i = i + 1: Count = Count + 1 
      Loop 

      ActiveCell.Offset(0, i).Select 
      With Selection.Interior 
       .Pattern = xlSolid 
       .PatternColorIndex = xlAutomatic 
       .ThemeColor = xlThemeColorAccent3 
       .TintAndShade = -0.249977111117893 
       .PatternTintAndShade = 0 
      End With 
     Next i 

     Count = Right(col, Len(col) - InStr(1, col, ".")) 

     If Count > 0 And Count < 25 Then 
      ActiveCell.TintAndShade = -4.99893185216834E-02 
     ElseIf Count > 26 And Count < 50 Then 
      ActiveCell.TintAndShade = 0.799981688894314 
     ElseIf Count > 75 And Count < 100 Then 
      ActiveCell.TintAndShade = 0.599993896298105 
     End If 
    ' ****** Next y out of place ****** 
    Next y 

    End If 
Next y 

(아래 들여 쓰기 코드 참조), 다음 코드 내 데이터 시트에 일이 :

Sub test_yRange() 

Dim rng  As Range 
Dim y  As Range 

Set rng = Worksheets("Sheet1").Range("A1:D5") 


For Each y In rng 
    ' working now 
    If Not IsEmpty(y) And y > 7.5 And y <> "" And IsNumeric(y) Then 
     ' I am passing the If above when a certain cell has a value of 8 
     y.Select 
     With ActiveCell.Offset(0, i).Interior 
      .Pattern = xlSolid 
      .PatternColorIndex = xlAutomatic 
      .ThemeColor = xlThemeColorAccent3 
      .TintAndShade = -0.249977111117893 
      .PatternTintAndShade = 0 
     End With 
    End If 
Next y 


End Sub 
+0

유용한 답변 이었지만 ActiveCell.Offset (0, i) .TintAndShade = -0.149998474074526 과 같이 질문에 완전히 대답하지 않았습니다. 지원되는 속성이 아닙니다. 따라서 코드가 올바르게 작동하지 않습니다. – Lowpar

관련 문제