+ Reply to Thread
Results 1 to 8 of 8

cut and copy an entire row based on value in a cell

  1. #1
    Registered User
    Join Date
    10-04-2013
    Location
    Ferryhill
    MS-Off Ver
    Excel 2010
    Posts
    25

    cut and copy an entire row based on value in a cell

    Hi,

    I have a spread sheet containing a list of tasks. The first sheet is called "Press Shop", I also have a sheet called "archive". When a task is complete, column J is set to complete. I am looking for some code that will cut this entire row out of the "Press Shop" sheet, move the cells up, and copy it to the bottom of the list in "archive".

    Can anyone help me please?

    Code I have so far.

    Sub As_Of_Analysis_Sorting()

    Dim lr As Long
    Dim lr2 As Long
    Dim r As Long

    lr = Sheets("Press Shop").Cells(Rows.Count, "A").End(xlUp).Row
    lr2 = Sheets("Archived Changes").Cells(Rows.Count, "A").End(xlUp).Row

    For r = lr To 2 Step -1
    If Range("J" & r).Value = "Complete" Then
    Rows(r).Copy Destination:=Sheets("Archived Changes").Range("A" & lr2 + 1)
    lr2 = Sheets("Archived Changes").Cells(Rows.Count, "A").End(xlUp).Row
    End If
    Next r

    End Sub
    It's repeating some rows twice, and obviously not deleting rows yet


    Thanks
    Last edited by michaelcouch87; 11-26-2013 at 04:56 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: cut and copy an entire row based on value in a cell

    Hi, michaelcouch87,

    maybe like this
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: cut and copy an entire row based on value in a cell

    Another:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-04-2013
    Location
    Ferryhill
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: cut and copy an entire row based on value in a cell

    Thanks people.

    I now have code that will get me by for now, however, how can I make this an automatic process for say when it is first changed to complete, or on closing a work book, is this possible or will I need an archive button?

    Thanks

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: cut and copy an entire row based on value in a cell

    Hi, michaelcouch87,

    you could call any of the macros from any event being raised in the Workbook (either ThisWorkbook: Workbook_Open, Workbook_BeforeSave, Workbook_BeforeClose, behind a Worksheet: Worksheet_Activate or Worksheet_Deactivate). This action would request that you save the workbook after the code is run.

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    10-04-2013
    Location
    Ferryhill
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: cut and copy an entire row based on value in a cell

    Thanks,

    Being a pain here, I now want to add a date stamp on to the end of a copied row in the Archived spread sheet. Is this a possibility?

    Also I'm UK based, could anybody suggest any decent books that I could learn VBA from, I had a one from my first year of uni, but cannot find it, that was for us in VIsual Studio but I imagine it may be the same.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: cut and copy an entire row based on value in a cell

    Hi, michaelcouch87,

    if the data is going through all columns you might like to try something like
    Please Login or Register  to view this content.
    If you want Date and Time inserted you might use Now instead of Date.

    you might have a look at this thread to find hints on online material as well as books.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    10-04-2013
    Location
    Ferryhill
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: cut and copy an entire row based on value in a cell

    Thanks Mate Works Fine

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. vba - copy entire row based on cell value
    By Zygoid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2013, 12:25 PM
  2. [SOLVED] Copy entire row to appropriate sheet based on value of cell in row E
    By engineerjason in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 11-12-2012, 07:48 PM
  3. Copy/Cut entire row to another sheet based on cell value
    By excelkeechak in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-02-2010, 04:23 PM
  4. How do you copy an entire row in excel to a new tab based on a cell value
    By pklimchuk in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 10-20-2010, 04:42 AM
  5. How do you copy an entire row in excel to a new tab based on a cell value
    By pklimchuk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2010, 01:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1