# copy row based on cell value

#### mplees

##### Active Member
Hi,

I've been using the following code to highlight specific rows in my workbook - if a cell in column K contains 1, then the cell is highlighted in red

Code:
``````Dim CurCell as Range
Dim lRows as long

lRows = ActiveSheet.Rows.Count

For Each CurCell in ActiveSheet.Range("K:K")
If CurCell.Value = 1 Then CurCell.Interior.ColorIndex = 3
Next CurCell``````

...which seems to work fine. What I need to do now however, is to copy each row that contains 1 in column K to another sheet in the workbook, & then clear the original contents. e.g if my data is on row 8, copy the data from A8:K8 to the next empty row on Sheet 2. I've been playing around, but haven't been able to find a way to do this correctly - can anyone assist?

Regards,

Mark

### Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

#### Lewiy

##### Well-known Member
Try this:
Code:
``````Dim Limit As Long
Dim c As Long
Dim DestRow As Long
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
Limit = sh1.Cells(Rows.Count, 11).End(xlUp).Row
DestRow = sh2.Cells(Rows.Count, 1).End(xlUp).Row + 1
For c = Limit To 1 Step -1
If sh1.Cells(c, 11) = 1 Then
sh2.Range("A" & DestRow & ":K" & DestRow).Value = sh1.Range("A" & c & ":K" & c).Value
sh1.Rows(c).Delete shift:=xlUp
DestRow = DestRow + 1
End If
Next c``````

#### mplees

##### Active Member
Hi Lewiy,

Many thanks for that - works a treat!

Mark

Replies
19
Views
769
Replies
8
Views
292
Replies
3
Views
349
Replies
14
Views
785
Replies
2
Views
202

1,181,418
Messages
5,929,796
Members
436,695
Latest member
yashpisat

### 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.

### Which adblocker are you using?

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

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