VBA Help: Pull from Sheet1 to Sheet2 under Conditions

ragnar12

Board Regular
Joined
May 1, 2013
Messages
119
This should be simple....I just can't seem to get it to run right.
Goal: Pull in column A from Sheet1 to Sheet 2 (starting at Row 2) where Sheet1 Column BR (70)> 0 AND Column N (14) = Var1/2/3.

Issue: Currently it does pull in the correct rows, but it pulls them in at the same row number from Sheet1 into Sheet2. I would like it to start at Row 2 and then go from there. I'm sure an Array would probably speed this up, but I want to get the proof of concept before adding that.

Code:
VBA Code:
Sub add_NY_totals()

Dim r As Long
Dim y As Long
        'For r = 2 To Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
        For r = 2 To 200
            If Sheets("Sheet1").Cells(r, 14) = "Var1" Or _
                Sheets("Sheet1").Cells(r, 14) = "Var2" Or _
                Sheets("Sheet1").Cells(r, 14) = "Var4" Or _
                Sheets("Sheet1").Cells(r, 14) = "Var5" _
            Then
                Sheets("Sheet1").Cells(r, "BR") = WorksheetFunction.Sum(Range("AG" & r & ":AR" & r))
            End If
        Next r

        For y = 2 To 200
            If Sheets("Sheet1").Cells(y, "BR") > 0 And _
                Sheets("Sheet1").Cells(y, 14) = "Var1" Or _
                Sheets("Sheet1").Cells(y, 14) = "Var2" Or _
                Sheets("Sheet1").Cells(y, 14) = "Var4" _
            Then
                Sheets("Sheet2").Cells(y, 1).Value = Sheets("Sheet1").Cells(y, 1)
            End If
        Next y

End Sub

Thanks for any help or advice you can lend. I feel like this should be easy, but I've been looking at it for several hours to no avail....
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,421
Messages
6,124,806
Members
449,191
Latest member
rscraig11

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