Wpis z mikrobloga

#pytanie #programowanie #vba #excel

Sub ShadeEveryOtherRow()
Dim Counter As Integer

'For every row in the current selection...
For Counter = 1 To Selection.Rows.Count
'If the row is an odd number (within the selection)...
If Counter Mod 2 = 1 Then
'Set the pattern to xlGray16.
Selection.Rows(Counter).Interior.Pattern = xlSolid
Selection.Rows(Counter).Interior.Pattern = xlSolid
Selection.Rows(Counter).Interior.PatternColorIndex = xlAutomatic
Selection.Rows(Counter).Interior.ThemeColor = xlThemeColorAccent4
Selection.Rows(Counter).Interior.TintAndShade = 0.399945066682943
Selection.Rows(Counter).Interior.PatternTintAndShade = 0
End If
Next

End Sub

znalazłem taki kod na kolorowanie co drugiego wiersza w zaznaczeniu, i dziala. pytanie mam takie - czy mozna zmienic ten kod zeby kolorowal co 3,4,5 wiersz? i czy mozna zmienic go tak zeby zaczynal kolorowanie np. w przypadku kolorowania co 2. to zeby zaczynal od drugiego wiersza, kolorowanie co 3. zeby zaczynal od 3. itd.
  • 5
  • Odpowiedz
If Counter Mod 2 = 1 Then


@turbine: If Counter Mod 2 = 1 Then
Zmien na If Counter Mod 3 = 0 Then
Wtedy masz dokładnie co 3 wiersz pokolorowany
W obecnym stanie kod dziala tak, ze jezeli reszta z dzielenia przez 2 to 1. to kolorujesz
  • Odpowiedz
@turbine:
Sub ShadeEveryOtherRow()
Dim Counter As Integer

'For every row in the current selection...
For Counter = 1 To Selection.Rows.Count step [tutaj wstaw liczbe co który wiersz ma kolorować]
'If the row is an odd number (within the selection)...

'Set the pattern to xlGray16.
Selection.Rows(Counter).Interior.Pattern = xlSolid
Selection.Rows(Counter).Interior.Pattern = xlSolid
Selection.Rows(Counter).Interior.PatternColorIndex = xlAutomatic
Selection.Rows(Counter).Interior.ThemeColor = xlThemeColorAccent4
Selection.Rows(Counter).Interior.TintAndShade = 0.399945066682943
Selection.Rows(Counter).Interior.PatternTintAndShade = 0

Next

End Sub
  • Odpowiedz
  • 0
@kucinov: @Mrowka77 udalo mi sie zrobic zeby kolorowaly kazdy z 3 wierszy i tak po kolei w kazdym zaznaczeniu.

Sub koloruj3()
Dim Counter As Integer

'For every row in the current selection...
For Counter = 1 To Selection.Rows.Count
'If the row is an odd number (within the selection)...
If Counter Mod 3 = 1 Then
'Set the pattern to xlGray16.
Selection.Rows(Counter).Interior.Pattern = xlSolid
Selection.Rows(Counter).Interior.PatternColorIndex = xlAutomatic
Selection.Rows(Counter).Interior.ThemeColor = xlThemeColorAccent1
Selection.Rows(Counter).Interior.TintAndShade =
  • Odpowiedz
@turbine:
Z ciekawosci - musi byc vba? Bo mozna tez formatowaniem warunkowym w oparciu o formule:
=MOD(ROW(),2)=1
lub
=MOD(ROW(),2)=0
Zamiast 2 moze byc 3, 5, 7…n
I odpowiednie formatowanie do tego. Choc akurat to pewnie lepsze dla arkusaza a nie zaznaczenia tylko.
  • Odpowiedz