VBA Return Entire Row if Column Number is X

btoney

New Member
Joined
Mar 3, 2016
Messages
1
Hey all,

I am new to this forum and am only beginning to learn VBA. I am trying to create a VBA that will look to sheet "x" and return all of the rows in sheet "y" if column "s" in sheet "x" is greater than 5. I am getting an error with the first part of my code, which I titled "Sub Screener ()". Below is the code.

Code:
Sub Screener()
    Dim LR As Long, i As Long
    With Sheets("Sep.30.15")
        LR = .Range("T" & i)
            If .Value > 5 Then .EntireRow.Copy Destination:=Sheets("Screen").Range("A" & Rows.Count).End(xlUp).Offset(1)
            End With
        Next i
    End With
End Sub

Any help would be much appreciated.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Code:
Sub Screener()
    Dim i As Long
    With Sheets("Sep.30.15")
        For i = 2 To .Range("T" & Rows.Count).End(xlUp).Row
            With .Range("T" & i)
                If .Value > 5 Then .EntireRow.Copy Destination:=Sheets("Screen").Range("A" & Rows.Count).End(xlUp).Offset(1)
            End With
        Next i
    End With
End Sub
 
Upvote 0
Seems like it might be more efficient to use filters instead of loops for this type of thing.
 
Upvote 0
Seems like it might be more efficient to use filters instead of loops for this type of thing.
I would agree, but since he\she said they were learning, I thought it would be best to stick to their original loop method.
 
Upvote 0
I would agree, but since he\she said they were learning, I thought it would be best to stick to their original loop method.
That's fine. I figured as long as they are learning VBA (and not just loops in particular), they may also want to consider other options which may be more efficient (or at least just be aware that such options exist).

btoney,
If you are just learning VBA, a great tool is the Macro Recorder. You can use it to record yourself perform many actions. This is a great way to get code snippets which you can insert into your program.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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