Highlight Entire Row based on single cell value

upcea

New Member
Joined
Mar 14, 2011
Messages
20
HELP! I have a huge spreadsheet that i need to select a bunch of rows. the rows i need to highlight are contingent on data in a single cell in column AA. How do I do this?

Once I highlight the rows, I would like to copy and paste in another sheet and maintain the blank rows that were not highlighted...make sense?

THANKS! and happy monday :/
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Maybe like this- change the value in red to suit

Rich (BB code):
Sub CopyRows()
Dim c As Range, r As Range
For Each c In Columns("AA").SpecialCells(xlCellTypeConstants)
    If c.Value = "Copy" Then
        If r Is Nothing Then
            Set r = c
        Else
            Set r = Union(r, c)
        End If
    End If
Next c
If Not r Is Nothing Then
    With r.EntireRow
        .Copy Destination:=Sheets("Sheet2").Range("A1")
        .Delete
    End With
End If
End Sub
 
Upvote 0
ehhhh i have no idea what that means....do you have laymens terms?

im sorry- such a pain.
 
Upvote 0
Press ALT + F11 to open the Visual Basic Editor. Select Module from the Insert menu then paste the code into the white space on the right. Change my red Copy to your criterion in column AA. Press ALT + Q to close the code window.

Press ALT + F8 then double click CopyRows in the dialog box which should appear.
 
Upvote 0
When I do this I get an error message and when i click DEBUG it brings me back to the Microsof Visual Basic and ".Copy Destination:=Sheets("Sheet2").Range("A1")" is Highlighted yellow.

any suggestions?
 
Upvote 0
OH WAIT! I got it but when I go to the new sheet the spacing is not right. All rows are filled. i wanted the blank rows where the row was not selected, make sense?
 
Upvote 0
You will need to change Sheet2 to the name of the sheet to copy to. This sheet must exist.
 
Upvote 0
Try like this

Code:
Sub CopyRows()
Dim c As Range, r As Range
For Each c In Columns("AA").SpecialCells(xlCellTypeConstants)
    If c.Value = "Copy" Then
        If r Is Nothing Then
            Set r = c
        Else
            Set r = Union(r, c)
        End If
    End If
    c.EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & c.Row)
Next c
If Not r Is Nothing Then r.EntireRow.Delete
End Sub
 
Upvote 0
Didn't work :( the first one was right but the spacing is wrong. for example: if I'm copying rows 2,5,6,7,10 then in the new spreadsheet I only want data in those rows. and row 1,3,4,8,9 will be blank. is that possible?

seriously thank you so much for your help!
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top