ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Hi need help with RowSelection (https://www.excelbanter.com/excel-discussion-misc-queries/151049-hi-need-help-rowselection.html)

M&M[_2_]

Hi need help with RowSelection
 
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??


BigPig

Hi need help with RowSelection
 
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

"M&M" wrote:

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??


M&M[_2_]

Hi need help with RowSelection
 
Thank you for your fast response! I will do just that thanks

"BigPig" wrote:

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

"M&M" wrote:

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??


Rick Rothstein \(MVP - VB\)

Hi need help with RowSelection
 
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??



Bob Phillips

Hi need help with RowSelection
 
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)



"M&M" wrote in message
...
Thank you for your fast response! I will do just that thanks

"BigPig" wrote:

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

"M&M" wrote:

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??




Rick Rothstein \(MVP - VB\)

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??




Bob Phillips

Hi need help with RowSelection
 
That 0 should be xlColorindexNone

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Bob Phillips" wrote in message
...
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)



"M&M" wrote in message
...
Thank you for your fast response! I will do just that thanks

"BigPig" wrote:

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

"M&M" wrote:

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??






M&M[_2_]

Hi need help with RowSelection
 
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





"Rick Rothstein (MVP - VB)" wrote:

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??





BigPig

Hi need help with RowSelection
 
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

"M&M" wrote:

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



M&M[_2_]

Hi need help with RowSelection
 
Thanks once more. Deeply appreciate it. Have a wonderful day

"BigPig" wrote:

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

"M&M" wrote:

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




All times are GMT +1. The time now is 11:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com