English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i need to change this macro to instead of delete row, change the color of the entire row, highlight it or something.

Sub DeleteRows()
Dim c As Range
Dim SrchRng As Range
Dim SrchStr As String

Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
SrchStr = InputBox("Please Enter A Search String")
Do
Set c = SrchRng.Find(SrchStr, LookIn:=xlValues)
If Not c Is Nothing Then c.EntireRow.Delete
Loop While Not c Is Nothing

End Sub

2007-10-18 03:14:58 · 5 answers · asked by Leosphere 2 in Computers & Internet Programming & Design

5 answers

change Delete to Interior.ColorIndex = {num}

You can use the link below to see the possible values for ColorIndex

2007-10-18 03:29:52 · answer #1 · answered by Modest 5 · 0 0

Sub HighlightRows()
Dim c As Range
Dim SrchRng As Range
Dim SrchStr As String
Dim firstAddress As String

Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
SrchStr = InputBox("Please Enter A Search String")

Set c = SrchRng.Find(SrchStr, LookIn:=xlValues)
firstAddress = c.Address
Do
If Not c Is Nothing Then
c.EntireRow.Interior.Color = RGB(0, 200, 200)
Set c = SrchRng.FindNext(c)
End If
Loop While Not c Is Nothing And c.Address <> firstAddress

End Sub

2007-10-18 03:48:08 · answer #2 · answered by Anonymous · 0 0

You only need to change one thing. Change the following portion from:

c.EntireRow.Delete

To

c.EntireRow.Interior.ColorIndex = 3

The color index ranges from 1 to 56. Try different numbers to get the color you want. It returns the colors based on the colors in your color pallette.

There are only 56 colors available to use in Excel at one time.

You can reset a color in the color pallette though by doing the following:

ActiveWorkbook.Colors(3) = RGB(255, 0, 0)
c.EntireRow.Interior.ColorIndex = 3

The RGB function controls the amount of red, green, and blue added to the colors RGB(red, green, blue). The value for the amount of each color can range from 0 to 255. So on this instance, I made sure that number three of the color index equals red. If I wanted to make it purple I could enter the following:

ActiveWorkbook.Colors(3) = RGB(255, 0, 255)
c.EntireRow.Interior.ColorIndex = 3

Basically what both of those examples do is reset the third color in the color pallette (made up of 56 customizable colors). I customized the third color in the pallet to red in the first example and purple in the second one. Then I used that customized color to color the row.

2007-10-18 03:53:21 · answer #3 · answered by devilishblueyes 7 · 1 0

there is an elementary thanks to attempt this and also you do not opt for an advanced macro like the only the only answerer gave you. pass to: strategies > Macro > Macros... Then pick your macro and click the Edit button. Then replace the code between the "Sub" and "end Sub" lines with: With decision .Borders(xlDiagonalDown).LineStyle = xlNone .Borders(xlDiagonalUp).LineStyle = xlNone end With With decision.Borders .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic end With you should remove the diagonal lines if there are any. And the Borders series you should use to set the 4 edges. you do not opt for the lots of code Garbo wrote.

2016-10-21 08:54:51 · answer #4 · answered by Anonymous · 0 0

Recording is the best way to learn what objects and functions to use in a macro language.
Start recording a new macro, select a range, then change the colour. Stop recording then read the source code until you understand it. The recorded code will show you how to change the colour of a row, you just need to apply that code to your own macro.

2007-10-18 03:29:46 · answer #5 · answered by Mantrid 5 · 0 0

fedest.com, questions and answers