![]() |
Select Entire Row if Text is Red
My macro, below, is not working:
Sub SelIfRed() Dim rng As Range, c As Range Set rng = Selection For Each c In rng If cell.Font.ColorIndex = 3 Then ' Change if not correct value for rng.EntireRow.Select End If Next c End Sub It fails he If cell.Font.ColorIndex = 3 Then I can't see what the problem is. Can anyone see something that I'm not seeing? Thanks, Ryan--- -- RyGuy |
Select Entire Row if Text is Red
If c.Font.ColorIndex = 3 Then
c.EntireRow.Select because you are looping on the c range variable -- Gary''s Student - gsnu200752 "ryguy7272" wrote: My macro, below, is not working: Sub SelIfRed() Dim rng As Range, c As Range Set rng = Selection For Each c In rng If cell.Font.ColorIndex = 3 Then ' Change if not correct value for rng.EntireRow.Select End If Next c End Sub It fails he If cell.Font.ColorIndex = 3 Then I can't see what the problem is. Can anyone see something that I'm not seeing? Thanks, Ryan--- -- RyGuy |
Select Entire Row if Text is Red
Thanks GS! That solved the problem with the error, but it just loops through
all cells in the selected range, and ends on the last row with red text in it. I guess the issue is more complicated that that, because when the Sub ends, only one row is selected. Now, I am working with the code below, and again it is giving me a problem. Does anyone have an idea about what to do now? All I want to do is select an entire row if it has any red text in it, and copy/paste these rows into a new sheet. Sub Select_Red_Fonts() Dim c As Range, SearchRange As Range, cell As Range, redFonts As Range, x Set SearchRange = Cells.SpecialCells(xlCellTypeConstants) For Each c In SearchRange If cell.Font.ColorIndex = 3 Then 'c.EntireRow.Select If x = 1 Then Set redFonts = Union(redFonts, cell) Else Set redFonts = cell x = 1 End If End If Next c c.EntireRow.Select redFonts.Select Worksheets.Add.Name = "Summary" Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End Sub Thanks, Ryan--- -- RyGuy "Gary''s Student" wrote: If c.Font.ColorIndex = 3 Then c.EntireRow.Select because you are looping on the c range variable -- Gary''s Student - gsnu200752 "ryguy7272" wrote: My macro, below, is not working: Sub SelIfRed() Dim rng As Range, c As Range Set rng = Selection For Each c In rng If cell.Font.ColorIndex = 3 Then ' Change if not correct value for rng.EntireRow.Select End If Next c End Sub It fails he If cell.Font.ColorIndex = 3 Then I can't see what the problem is. Can anyone see something that I'm not seeing? Thanks, Ryan--- -- RyGuy |
Select Entire Row if Text is Red
Answer is he
http://www.microsoft.com/office/comm...2fsettings.xml -- RyGuy "ryguy7272" wrote: Thanks GS! That solved the problem with the error, but it just loops through all cells in the selected range, and ends on the last row with red text in it. I guess the issue is more complicated that that, because when the Sub ends, only one row is selected. Now, I am working with the code below, and again it is giving me a problem. Does anyone have an idea about what to do now? All I want to do is select an entire row if it has any red text in it, and copy/paste these rows into a new sheet. Sub Select_Red_Fonts() Dim c As Range, SearchRange As Range, cell As Range, redFonts As Range, x Set SearchRange = Cells.SpecialCells(xlCellTypeConstants) For Each c In SearchRange If cell.Font.ColorIndex = 3 Then 'c.EntireRow.Select If x = 1 Then Set redFonts = Union(redFonts, cell) Else Set redFonts = cell x = 1 End If End If Next c c.EntireRow.Select redFonts.Select Worksheets.Add.Name = "Summary" Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End Sub Thanks, Ryan--- -- RyGuy "Gary''s Student" wrote: If c.Font.ColorIndex = 3 Then c.EntireRow.Select because you are looping on the c range variable -- Gary''s Student - gsnu200752 "ryguy7272" wrote: My macro, below, is not working: Sub SelIfRed() Dim rng As Range, c As Range Set rng = Selection For Each c In rng If cell.Font.ColorIndex = 3 Then ' Change if not correct value for rng.EntireRow.Select End If Next c End Sub It fails he If cell.Font.ColorIndex = 3 Then I can't see what the problem is. Can anyone see something that I'm not seeing? Thanks, Ryan--- -- RyGuy |
All times are GMT +1. The time now is 12:20 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com