2016-08-26 4 views
0

매크로 레코더를 사용하여 코드를 작성하면 커다란 효과가 있습니다. 기본적으로 범위를 선택하고 두 가지 조건부 서식을 적용한 후 다음 범위로 이동합니다. 조건부 형식이 각 범위에 AVERAGE을 적용하기 때문에 한 번에 전체 범위를 선택할 수 없습니다. 나는 그것이 부끄러운 알고다양한 범위에 동일한 매크로 적용

Sub DesvPad() 

    Range("C3:N3").Select 
    Selection.FormatConditions.AddAboveAverage 
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority 
    Selection.FormatConditions(1).AboveBelow = xlAboveStdDev 
    With Selection.FormatConditions(1).Interior 
     .PatternColorIndex = xlAutomatic 
     .Color = 5296274 
     .TintAndShade = 0 
    End With 
    Selection.FormatConditions(1).NumStdDev = 1 
    Selection.FormatConditions(1).StopIfTrue = False 
    Selection.FormatConditions.AddAboveAverage 
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority 
    Selection.FormatConditions(1).AboveBelow = xlBelowStdDev 
    With Selection.FormatConditions(1).Interior 
     .PatternColorIndex = xlAutomatic 
     .Color = 49407 
     .TintAndShade = 0 
    End With 
    Selection.FormatConditions(1).NumStdDev = 1 
    Selection.FormatConditions(1).StopIfTrue = False 
MsgBox "O macro foi executado até Range(C325:N325)" 

End Sub 

, 그래서 어떤 도움을 주셔서 감사합니다 :

다음은 코드 조각입니다!

+0

"더"모듈 "코드를 만드는 방법을 요구하고 생각합니다 무엇을 요구하고 있는지 확실하지 않습니다. 여러분이 말한 것은 여러분이 원하는 것과 코드가있는 거대한 코드 조각을 가지고 있다는 것입니다. 어떤 문제를 수정하거나 개선하려고합니까? – viper941

+0

코드를 사용할 수 있습니까? 통합 문서의 모든 시트에, 또는 당신이 원하는 시트 수 있습니다 ... –

답변

0

그것은 당신의 질문이 무엇인지 정말 분명하지 않다하지만 난 당신이

Sub Tester() 
    ApplyCF Range("A1:A10") 
    ApplyCF Range("A11:A20") 
    'etc 
End Sub 


Sub ApplyCF(rng As Range) 

    'here use rng instead of "Selection" 
    rng.FormatConditions.AddAboveAverage '<< for example 

End Sub 
+0

안녕! 귀하의 답변에 감사드립니다. 나는 당신의 코드를 수정하려했지만 여기에 게시 할 수 없다. ("N3 C3") 최종 Sub' '서브 ApplyCF (범위로서 RNG) rng.FormatConditions.AddAboveAverage rng.FormatConditions.AddAboveAverage rng.FormatConditions (선택() ApplyCF 범위 – Serveira

+0

'서브 테스터 .FormatConditions.Count) .SetFirstPriority rng.FormatConditions (1) .AboveBelow = xlAboveStdDev rng.FormatConditions (1) .Interior .PatternColorIndex = xlAutomatic = 5296274 TintAndShade = 0 끝 Sub' 내가 갖는 – Serveira

+0

색 그것이 시도 할 때의 오류 pply 색상! 내가 도대체 ​​뭘 잘못하고있는 겁니까? – Serveira

0

난이 도움이 될 생각 :

Sub formatInMySelectedSheets() 'use this just for few sheet 
           'that you want to change 
    Dim i As Worksheet 
    Dim Nm(1 To 3) As String 
    Dim s 
    Dim sht As Worksheet 

    'Imagine the book has 10 sheets, "Sheet1" to "Sheet10" 
    'but you only want to go to Sheet1, Sheet4 and Sheet7 

    Nm(1) = "Sheet1" 'this are the sheets you want to change 
    Nm(2) = "Sheet4" 
    Nm(3) = "Sheet7" 

    For Each i In ActiveWorkbook.Worksheets 'the workbook with the sheets... 

     For s = LBound(Nm) To UBound(Nm) 'from the lowest value of the array to 
             'to the highest 
      Set sht = Sheets(Nm(s)) 
      'here the code shows the sheet to avoid some errors 
      'if the sheet is hidden, Show it to me! 
      If sht.Visible = xlSheetVeryHidden Or sht.Visible = xlSheetHidden Then 
       sht.Visible = xlSheetVisible 
      End If 
      'go to the sheet 
      sht.Activate 
      DesvPad 'Calls you code 
     Next s 
    Next i 
End Sub 

Sub formatInEverySheet() 'Use this to do it in every sheet 
         'no matter what! 
    Dim i As Worksheet 
    For Each i In ActiveWorkbook.Worksheets 
     i.Activate 
     ' here the code shows the sheet to avoid some errors 
     If i.Visible = xlSheetVeryHidden Or i.Visible = xlSheetHidden Then 
      i.Visible = xlSheetVisible 
     End If 
     DesvPad 'Calls you code 
    Next i 
End Sub 
관련 문제