+ Reply to Thread
Results 1 to 8 of 8

Moving an entire row based on a cell having a date in it.

  1. #1
    Registered User
    Join Date
    08-28-2018
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    27

    Moving an entire row based on a cell having a date in it.

    Hi everyone,

    I have this VBA code that I found and it works but only if the cell is filled in with "Done". However I would like to have it move the row of cells when there is a returned date put in. The other thing is also that the dates will always be different. So is there a way to move it with the cell just having anything in it? Also is there a way to have this be done automatically once data is in the column G location?

    Sub Cheezy()
    'Updated by Kutools for Excel 2017/8/28
    Dim xRg As Range
    Dim xCell As Range
    Dim I As Long
    Dim J As Long
    Dim K As Long
    I = Worksheets("Current borrows").UsedRange.Rows.Count
    J = Worksheets("Completed borrows").UsedRange.Rows.Count
    If J = 1 Then
    If Application.WorksheetFunction.CountA(Worksheets("Completed borrows").UsedRange) = 0 Then J = 0
    End If
    Set xRg = Worksheets("Current borrows").Range("G1:G" & I)
    On Error Resume Next
    Application.ScreenUpdating = False
    For K = 1 To xRg.Count
    If CStr(xRg(K).Value) = "Done" Then
    xRg(K).EntireRow.Copy Destination:=Worksheets("Completed borrows").Range("A" & J + 1)
    xRg(K).EntireRow.Delete
    If CStr(xRg(K).Value) = "Done" Then
    K = K - 1
    End If
    J = J + 1
    End If
    Next
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Moving an entire row based on a cell having a date in it.

    Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your Current borrows sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make an entry in column G and press the RETURN key. You can delete your previous macro.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    08-28-2018
    Location
    Oregon
    MS-Off Ver
    2010
    Posts
    27

    Re: Moving an entire row based on a cell having a date in it.

    That works perfectly. Thank you very much.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Moving an entire row based on a cell having a date in it.

    You are very welcome.

  5. #5
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Moving an entire row based on a cell having a date in it.

    Here is another option, although not as efficient as @Mumps1

    In the workbook sheet module list the following:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,394

    Re: Moving an entire row based on a cell having a date in it.

    Mumps,

    Elegant code, but should the 'set' statements not be reset to Nothing at the end of the Macro?

    I had it drummed into me back in the Dark Ages that if you really need a variable, set it to Nothing once you don't need it anymore, because Excel doesn't always release the 'addressed' memory when the lifespan of that variable ends, especially if it is 'scoped' for the module, and even more so if it's scoped globally.

    Value your insight

    Ochimus

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Moving an entire row based on a cell having a date in it.

    To be honest, I've never had any issues by not re-setting variables to nothing but that is due perhaps to the way I define and use them. The following links may help.
    https://docs.microsoft.com/en-us/off...e-of-variables
    https://bettersolutions.com/vba/vari...as%20completed.

  8. #8
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,394

    Re: Moving an entire row based on a cell having a date in it.

    Mumps,

    I accept this could be a "how many angels can stand on the head of a pin" concern, especially for newcomers, and I appreciate the links you provided, but the MS document itself actually points out that 'Module-level' variables consume memory resources until you reset their values?

    Which seems to support what I had hammered into me when I started using Excel.

    Of course, not doing it gives you an excellent "cover story" when a Code takes longer than a carrier pigeon to do something simple, as we've all experienced at some point. . .

    Ochimus

+ 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 To Copy An Entire Row To A New Sheet Based On The Date In A Cell.
    By DIHayman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-01-2020, 09:26 AM
  2. High light entire row based on cell DATE value
    By shayma in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2017, 09:18 AM
  3. [SOLVED] moving formula/cell based on date
    By RE_NERO in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-24-2016, 02:49 PM
  4. [SOLVED] Moving an entire row based on one cell's value, but not deleting the row from the master.
    By philwojo in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-27-2014, 02:01 PM
  5. [SOLVED] Moving entire row from one spreadsheet to another based on content in a particular cell
    By appchick21 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-11-2013, 02:30 AM
  6. Moving an entire row to new worksheet based on variable cell value.
    By aovermille in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2012, 03:52 PM
  7. Moving formulas in a cell based on date entry ?
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2010, 01:52 PM

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