View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Hi need help with RowSelection

Just to give you the "theory" behind my posting... if you have two numbers
you wish to toggle between, simply subtract the variable from the sum of
those two numbers. For example.

Const Num1 = 17
Const Num2 = 43
Const Sum = Num1 + Num2
' Initialize the variable to one of these values
If Variable < Num1 And Variable < Num2 Then Variable = Num1
Variable = Sum - Variable

Every time you execute the above code, the Variable will toggle between 17
(Num1) and 43 (Num2). If you think about it, this is obvious as the "toggle
line" is really this

Variable = (Num1 + Num2) - Variable

where Variable is either Num1 or Num2... subtracting one number from the sum
yields the other. That is,

(Num1 + Num2) - Num1 == Num2

(Num1 + Num2) - Num2 == Num1

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
Im sure this is an elementary question but I'd rather ask than to spend
two
hours trying to figure it out.

I have the macro below:

Sub ShadingMacro()
Dim i As Integer
i = 2
Do Until IsEmpty(Cells(i, 1))
Cells(i, 1).EntireRow.Interior.ColorIndex = 15


Changing the above line to this...

Cells(i, 1).EntireRow.Interior.ColorIndex = -4127 - Cells(i,
1).EntireRow.Interior.ColorIndex

will toggle the shading. The -4127 value is derived by adding your color
index value of 15 to the default color index of -4142.

Rick




i = i + 2
Loop
End Sub


How do I click that same command button again to undo the highlighted
rows??