Hi need help with RowSelection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
i = i + 2
Loop
End Sub


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

You could try using a toggle button instead of a cmd btn and use the same
procedure that you wrote, and then set the colorindex to 0 to change it back
to 'unhighlighted'. Or put in another cmd btn and use your code but change
the colorindex to 0.

hth

BigPig
 
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
 
Sub ShadingMacro()
Static fSet As Boolean
Dim iLastRow As Long
With ActiveSheet
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With Rows("1:" & iLastRow)
If fSet Then
.Interior.ColorIndex = 0
Else
.Interior.ColorIndex = 15
End If
End With
fSet = Not fSet
End With
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
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
 
That 0 should be xlColorindexNone

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Thanks to YOu all!!!!!
Greatly appreciate all of your support. Now theres another question I have.
A userform and when building this there is a image icon to input an image.
for some reason it seems that I cannot simply copy and paste an image into
the userform

How can I do this
 
Hi M&M,

First save the image as either bitmap or jpeg. In userform properties look
for picture. Click on the three little dots (...) to the right...
Then look for 'PicturePosition' to stretch, tile or whatever. Also, to
delete the picture, click in the field next to 'Picture' and hit the delete
key.

hth

BigPig
 
Back
Top