If Cell Is Blank, Copy Row to Other Sheet?

avisser

New Member
Joined
Jun 14, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi all, I hope you're doing great! I've got a sheet for each month of tenant info for a rental company. I'm trying to improve workflow by creating an "Urgent" sheet of people that haven't submitted a needed form, pulling from the other 12 sheets. This is marked in a column, and blank cells in this column need to have their corresponding rows copied to the "Urgent" sheet.

These rows start at '7' and the column we're checking for blanks is 'J'.

Thanks in advance, you guys are awesome!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Have a try with my macro. I'm assuming you have headers in row 6 of the sheet with the data and that column A always has data till last used row.
VBA Code:
Option Explicit
Sub Filter_Copy_Paste()
    Dim lr1     As Long
    Dim lr2    As Long
    With Sheets(1)                                '<- adjust sheet's name as needed
        lr1 = .Cells(Rows.Count, 1).End(xlUp).Row     'last used row in Sheet(1)
        .AutoFilterMode = False
        .Range("A6:J" & lr1).AutoFilter Field:=10, Criteria1:="=" 'filter range on blanks
        lr2 = Sheets("Urgent").Cells(Rows.Count, 1).End(xlUp).Row + 1 'first unused row in sheet "Urgent"
        .Range("A6:J" & lr1).Offset(1).SpecialCells(xlCellTypeVisible).Copy Sheets("Urgent").Range("A" & lr2) 'Copy/Paste
        .AutoFilterMode = False
    End With
End Sub
 
Upvote 0
Oh man, thank you so much Rollis! My first time using Macros so please bear with me. I've gotten the run-time error '1004': AutoFilter method of Range class failed. When I click 'Debug' I get this. All I've changed is the sheet name on line 4.

1655318814852.png


The Mini-Sheet extension keeps crashing Excel, so here's a screen shot if it helps. I'm trying to pull from 12 sheets all titled "JAN-22" "FEB-22" "MAR-22" and so on through the months, into "Urgent". Column A does have data, I've just deleted some things for confidentiality.

1655320106221.png


Thank you for everything my man!
 
Upvote 0
Your calculation of the last row (the "lr1" variable) is currently using the first column (column A):
Rich (BB code):
lr1 = .Cells(Rows.Count, 1).End(xlUp).Row
but it looks like you have no data in column A, so it is saying that row 6 is your last row, which is your title row, and you cannot filter a range with no data!

I think you need to use some other column to find the last row of data. It looks like column B might work, so change that row above to this:
Rich (BB code):
lr1 = .Cells(Rows.Count, 2).End(xlUp).Row
 
Upvote 0
Column A does have data, I've just edited the picture for confidentiality. Thank you though! Any other ideas?
 
Upvote 0
Did you try changing it column B anyway?
Did it make a difference?

Add this line after the line that calculate the last row ("lr1") and see what the Message Box returns:
VBA Code:
MsgBox "Last Row is " & lr1
 
Upvote 0
Terribly sorry but can't replicate your issue. The only possibility could be that variable lr1 is set to zero so while doing debug (please hover with the mouse over lr1 or look in the Local Variables pane or use @Joe4's suggestion in his post #6) to see what value it takes on. But there is no reason that it is zero.
 
Upvote 0
It says last row is 25 (there's some data cropped out in the photo). And that's with it set to column B. Thank you!
 

Attachments

  • 1655330044340.png
    1655330044340.png
    41.2 KB · Views: 2
Upvote 0
Terribly sorry but can't replicate your issue. The only possibility could be that variable lr1 is set to zero so while doing debug (please hover with the mouse over lr1 or look in the Local Variables pane or use @Joe4's suggestion in his post #6) to see what value it takes on. But there is no reason that it is zero.
Oh wow, thanks for the hover tip in debug! lr=25
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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