+ Reply to Thread
Results 1 to 14 of 14

I have a very simple vba macro, but I would delete row after I cut row to another sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    08-25-2020
    Location
    San Antonio, Texas
    MS-Off Ver
    365
    Posts
    7

    I have a very simple vba macro, but I would delete row after I cut row to another sheet

    I am new to vba macros and need help. I have a very simple vba macro, but I would like delete row after I cut row to another sheet and then shift remaining cells up


    a = Worksheets("Work Order Tracking Form").Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 3 To a
    
        If Worksheets("Work Order Tracking Form").Cells(i, 8).Value = "Complete" Then
    
            Worksheets("Work Order Tracking Form").Rows(i).EntireRow.Cut 
            Worksheets("Completed 2020").Activate
            b = Worksheets("Completed 2020").Cells(Rows.Count, 1).End(xlUp).Row
            Worksheets("Completed 2020").Cells(b + 1, 1).Select
            ActiveSheet.Paste
            Worksheets("Work Order Tracking Form").Activate
    
        End If
    
    Next
    Application.CutCopyMode = False
    
    ThisWorkbook.Worksheets("Work Order Tracking Form").Cells(1, 1).Select
    Last edited by alansidman; 08-25-2020 at 10:43 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

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

    Posting code between [CODE] [/CODE] 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



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    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
    08-25-2020
    Location
    San Antonio, Texas
    MS-Off Ver
    365
    Posts
    7

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    Ok, thank you.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    try something like this
    dim x as range
    a = Worksheets("Work Order Tracking Form").Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 3 To a
    
    If Worksheets("Work Order Tracking Form").Cells(i, 8).Value = "Complete" Then
        if x is nothing then
            set x=Worksheets("Work Order Tracking Form").Cells(i, 8)
        else
            set x = union(x,Worksheets("Work Order Tracking Form").Cells(i, 8))
        end if
    end if
    next
    if not x is nothing then
        x.entirerow.copy Worksheets("Completed 2020").Cells(Rows.Count, 1).End(xlUp)(2)
        x.entirerow.delete
    end if
    Application.CutCopyMode = False
    
    ThisWorkbook.Worksheets("Work Order Tracking Form").Cells(1, 1).Select
    Last edited by jindon; 08-25-2020 at 11:03 PM.

  5. #5
    Registered User
    Join Date
    08-25-2020
    Location
    San Antonio, Texas
    MS-Off Ver
    365
    Posts
    7

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    I'm getting an error on the last End If "end if without block if"

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    OOps, the code has been edited.

    You could also do it with AutoFilter, if you have header.

  7. #7
    Registered User
    Join Date
    08-25-2020
    Location
    San Antonio, Texas
    MS-Off Ver
    365
    Posts
    7

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    Now I'm getting an error
    x.entirerow.delete
    line. Sorry I'm new to vba and struggling

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    Can you show me the whole code?

  9. #9
    Registered User
    Join Date
    08-25-2020
    Location
    San Antonio, Texas
    MS-Off Ver
    365
    Posts
    7

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    Dim x As Range
    a = Worksheets("Work Order Tracking Form").Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 3 To a
    
    If Worksheets("Work Order Tracking Form").Cells(i, 8).Value = "Complete" Then
        If x Is Nothing Then
            Set x = Worksheets("Work Order Tracking Form").Cells(i, 8)
        Else
            Set x = Union(x, Worksheets("Work Order Tracking Form").Cells(i, 8))
        End If
    End If
    Next
    If Not x Is Nothing Then
        x.EntireRow.Copy Worksheets("Completed 2020").Cells(Rows.Count, 1).End(xlUp)(2)
        x.EntireRow.Delete
    End If
    Application.CutCopyMode = False
    
    ThisWorkbook.Worksheets("Work Order Tracking Form").Cells(1, 1).Select

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    And what kind of error are you getting?

  11. #11
    Registered User
    Join Date
    08-25-2020
    Location
    San Antonio, Texas
    MS-Off Ver
    365
    Posts
    7

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    x.EntireRow.Delete
    it turns yellow and says delete method of range class failed

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    Then I need to see your workbook, as it is working here.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    Or is the worksheet protected?

  14. #14
    Registered User
    Join Date
    08-25-2020
    Location
    San Antonio, Texas
    MS-Off Ver
    365
    Posts
    7

    Re: I have a very simple vba macro, but I would delete row after I cut row to another shee

    I ran my first macro and manually deleted columns then changed to your macro and yes it works. Thank you jindon

+ 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. Simple Macro to Delete an Excel file at a specific Folder Location
    By Davek11 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2019, 09:40 AM
  2. Run a simple goalseek macro in every sheet except a few
    By ChrisGeorge89 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-11-2019, 02:45 PM
  3. Simple macro to search text and delete any plus signs
    By fruitloop44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-21-2018, 01:18 PM
  4. Simple Macro: Delete mail in certain folders
    By Student1990 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 11-13-2013, 04:49 PM
  5. [SOLVED] Simple macro to create list of sheet names and the contents of cells A1 & N1 of each sheet
    By atcsmh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-15-2013, 11:11 AM
  6. Write a simple Macro to delete every alternative rows (1, 3, 5...)
    By kwfine in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2011, 02:45 AM
  7. Simple MACRO to delete words not required in ROWS
    By soni77 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2011, 10:58 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