Macro to cut and paste based on cell value

doublej41

Board Regular
Joined
Mar 9, 2011
Messages
86
Hi All,

I am looking for some help, with what I assume will require a macro.

I currently have a list of tasks on sheet 1 that are labelled as Open, In Progress or Closed using data validation in column K. When Closed is selected I would like that row to be cut and paste to the next available row on sheet 2.

Is there a straightforward way to get this working with a macro?

All responses will be gratefully received.

Jonathan
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi

Assuming you only want to cut columns A-J and not the data validation itself, put this in as a worksheet change event

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim LastR As Long, RowNum As Long

    If Selection.Count > 1 Then Exit Sub

    If Target.Column <> 11 Then Exit Sub

    If Target.Value = "Closed" Then

    RowNum = Target.Row


    LastR = Sheets("Sheet2").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row


  

    ActiveSheet.Range(Cells(RowNum, 1), Cells(RowNum, 10)).Cut _
    Destination:=Sheets("sheet2").Cells(LastR + 1, 1)

    End If


End Sub
 
Upvote 0
Hi nigelk

Many thanks for your reply.

When using the code I get the error "Run-time error 91: Object variable or With block variable not set".

When I click debug, it highlights the following row in yellow:

LastR = Sheets("Sheet2").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

Any suggestions as to why this might be? As you can probably sense, I am not too clued up when it comes to macros.
 
Upvote 0
After adding column headings, I am still getting the same error.

Do I need to change any of the code to match my workbook? All sheets still have their default names.
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

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