+ Reply to Thread
Results 1 to 11 of 11

Cut a row below the last row of a table

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Cut a row below the last row of a table

    Hello I am trying to write vba maybe someone can help me with this task. Every day I receive a report and I need to cut the rows where column D says NYMTR and Column N says Rollovered and move it to two rows below the table...

    Here is something that is not working for me:

    Sub MoveRows()
    
    FinalRow = Cells(1048576, 1).End(x1Up).Row
    For x = 1 To FinalRow
    
        If Cells(x, "N").Value = "Rollovered" And Cells(x, "D").Value = "NYMTR" Then
            ActiveCell.EntireRow.Cut Destination:=FinalRow+2
          
        End If
        Next x
    
    End Sub
    Last edited by alansidman; 02-17-2014 at 05:56 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,027

    Re: Cut a row below the last row of a table

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)

    You say it is not working. What does that mean. Are you getting an error message? If so, what is the message and what line is highlighted when you debug? Or, is nothing happening? Please clarify.
    Last edited by alansidman; 02-17-2014 at 05:59 PM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Cut a row below the last row of a table

    The first row is being highlighted

    FinalRow = Cells(1048576, 1).End(x1Up).Row

  4. #4
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Cut a row below the last row of a table

    It said application defined error or object defined error

    I got that line from an excel book though I don't know why it is causing an error.

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Cut a row below the last row of a table

    it also matters what the error is....since you don't have FinalRow dimensioned it's probably a variant. If your file is an .xls then the problem could be that you are only allowed ~65000 rows. You could try setting the 1048576 to 65000 and see what that does...but you need to determine what the actually max rows will be.....

    EDIT: Thanks for the error code....
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Cut a row below the last row of a table

    FinalRow = Cells(1048576, 1).End(xlUp).Row
    the 1 in x1Up should be the letter l (ell)

  7. #7
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Cut a row below the last row of a table

    Thanks judge, that helps get rid of the error message. However, now when I try to run the code it does not make any changes and no errors come up.

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Cut a row below the last row of a table

    have you stepped through the code to see what it is doing?....Is FinalRow getting set to something you think it should be set to?

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Cut a row below the last row of a table

    If you want to delete or cut a row, you should look back ward

    For x =  FinalRow to 1 step -1
    .

    If the code does nothing, it can only mean, this line is false

     If Cells(x, "N").Value = "Rollovered" And Cells(x, "D").Value = "NYMTR" Then
    In other words, both conditions do not return true

    Last use this line

    rows(x).cut FinalRow+2

  10. #10
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Cut a row below the last row of a table

    Right now I am getting an error that says cut method of range class failed.

    Tha last line is highlighted:

    Rows(x).Cut FinalRow + 2

    Sub macro1()
    FinalRow = Cells(1048576, 1).End(xlUp).Row
    
    For x = FinalRow To 2 Step -1
    If Cells(x, "E").Value = "Rollovered" And Cells(x, "C").Value = "Equity" Then
    Rows(x).Cut FinalRow + 2
    
    End If
    Next x
    
    End Sub

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Cut a row below the last row of a table

    I am not surprised you got an error.
    Where is FinalRow as you cut the rows?
    You also have a table where the last row might not work.

    You can try this line, but will come up with the same error

    Cells(x, "A").EntireRow.Cut FinalRow + 2
    You have probably complicated the issue by you are not using a filter function, or a different construction of loop.
    Attach a sample and will write you a code.

+ 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. [SOLVED] Summary table updated from source table. Source table held in a different workbook
    By dma1976 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-22-2013, 11:36 AM
  2. Replies: 0
    Last Post: 07-02-2013, 11:30 AM
  3. Replies: 0
    Last Post: 12-05-2012, 03:48 PM
  4. [SOLVED] Need a formula to sort a table into table (for a Table Plan) and name in column 2
    By jbpianoman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2012, 09:21 AM
  5. PIVOT TABLE - Summary Table into a Databasae Table.
    By sansk_23 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-09-2005, 03:06 AM

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