copy row based on cell value

mplees

Active Member
Joined
Feb 6, 2006
Messages
351
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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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
 
Upvote 0
Hi Lewiy,

Many thanks for that - works a treat!

Thanks again for your help,

Mark
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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