Need a macro to copy rows only when certain columns are completely empty

profklein

New Member
Joined
May 20, 2017
Messages
20
Hello all
I am cleaning my data in stages. For my first stage, I want to eliminate all the rows where my survey participant did not answer any questions (meaning he or she wasn't truly a participant). I will know this if columns F through BK are completely empty. So what is need is this: Starting with row 3 in sheet x, I want to copy that row into sheet y as long as columns F through BK are not COMPLETELY EMPTY. I want to do this for every row until the last.

Thank you in advance for helping me with my PhD.

Gene
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Here is an untested VBA solution

Code:
Option Explicit
Sub Foo()
    Dim x As Worksheet
    Dim y As Worksheet
    Set x = Sheets("SheetX")
    Set y = Sheets("SheetY")
    Dim i As Long, lr As Long
    Dim lry As Long
    Application.ScreenUpdating = False
    lr = x.Range("B" & Rows.Count).End(xlUp).Row
    For i = 3 To lr
        lr2 = y.Range("A" & Rows.Count).End(xlUp).Row + 1
        If Application.WorksheetFunction.Count(Range("F" & i & ":BK" & i)) > 0 Then
            x.Range("B" & i).EntireRow.Copy
            y.Range("A" & lry).PasteSpecial xlPasteValues
        End If
    Next i
    Application.ScreenUpdating = True
    Application.CutCopyMode = False
    MsgBox "Completed"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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