VBA mod

dantheram

Board Regular
Joined
Aug 27, 2010
Messages
192
Office Version
  1. 365
Platform
  1. Windows
Hi all,

can someone help me to mod this so that when the rows identified are moved to another sheet the subsequent blank row is deleted from the source table, please?

Code:
Sub Move_Closed()Dim Check As Range, r As Long, lastrow2 As Long, lastrow As Long
Application.ScreenUpdating = False
lastrow = Worksheets("Open").UsedRange.Rows.Count
lastrow2 = Worksheets("Completed").UsedRange.Rows.Count
If lastrow2 = 1 Then lastrow2 = 0
    For r = lastrow To 2 Step -1
        If Range("E" & r).Value = "Y" Then
            Rows(r).Cut Destination:=Worksheets("Completed").Range("A" & lastrow2 + 1)
            lastrow2 = lastrow2 + 1
            Else:
        End If
    Next r
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
In that case try
Code:
    If Not Rng Is Nothing Then Intersect(Rng, Sheets("Data").ListObjects([COLOR=#ff0000]1[/COLOR]).DataBodyRange).Delete
Change the value in red if needed.
 
Upvote 0
In that case try
Code:
    If Not Rng Is Nothing Then Intersect(Rng, Sheets("Data").ListObjects([COLOR=#ff0000]1[/COLOR]).DataBodyRange).Delete
Change the value in red if needed.

is the ListObjects(1) component referring to the table name within the xls? If so, does it need to be as follows - ListObjects("Table13")?
 
Upvote 0
No it's referring to the number, if you only have 1 table on the sheet then leave it as-is.
 
Upvote 0
No it's referring to the number, if you only have 1 table on the sheet then leave it as-is.

Spotted it - sheet name is wrong in my VBA, will try again

Dan
 
Last edited:
Upvote 0
No it's referring to the number, if you only have 1 table on the sheet then leave it as-is.


its working fine when i adjust the ListObjects(#) now. However, i have 2 tables on the sheet which i require it to act upon, so ListObjects(1) and ListObjects(2), how do i repeat the function for both?
 
Upvote 0
You'll need to change the range it loops through & the listobject number to match the other table
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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