Move Row

Johnboy

Board Regular
Joined
Oct 25, 2004
Messages
144
I use the following to move and delete row for a one worksheet, I would like one macro to do the same for all sheets except "Master" and "Discontinued" in the workbook.

Sub move_if_Discontinued()

r = 7
Do Until Sheets("Brick").Cells(r, 2).Value = ""

If Sheets("Brick").Cells(r, 10).Value = "Yes" Or _
Sheets("Brick").Cells(r, 10).Value = "YES" Or _
Sheets("Brick").Cells(r, 10).Value = "yes" Then

Sheets("Discontinued").Rows(7).EntireRow.Insert
Rng = "a" & r & ":k" & r
Sheets("Brick").Range(Rng).Copy _
Destination:=Sheets("Discontinued").Range("a7")

Sheets("Brick").Rows(r).EntireRow.Delete

End If

r = r + 1
Loop

End Sub

Thanks
Johnboy
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this code:

Code:
Sub move_if_Discontinued()

    Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets

        If ws.Name <> "Master" And ws.Name <> "Discontinued" Then

            r = 7
            Do Until ws.Cells(r, 2).Value = ""

                If UCase(ws.Cells(r, 10).Value) = "YES" Then

                    ThisWorkbook.Sheets("Discontinued").Rows(7).Insert
                    ws.Range("A" & r & ":K" & r).Copy Destination:=ThisWorkbook.Sheets("Discontinued").Range("A7")
                    ws.Rows(r).Delete

                End If

                r = r + 1

            Loop

        End If

    Next

End Sub

However, you are looping through the records in the wrong way: you should loop backwards (from last row to row 7). I'll leave this up to you.

Also, look at the other changes w.r.t. your initial macro.

Can you plus use
Code:
 tags? Thanks.
 
Upvote 0
Thanks wigi... Tried to download VB HTML Maker but my company has restricted certain downloads. Again thanks for your help.
 
Upvote 0
Thanks wigi... Tried to download VB HTML Maker but my company has restricted certain downloads. Again thanks for your help.

You should just type:

Code:
paste your code, and type again

[FORWARD SLASHcode]

Replace the FORWARD SLASH with /
 
Upvote 0

Forum statistics

Threads
1,224,893
Messages
6,181,616
Members
453,057
Latest member
LE102024

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