Code Help!!

asdaftasabrush

New Member
Joined
Feb 1, 2017
Messages
8
Anyone know why this line of code is failing?


Private Sub GenerateRedsNights_Click()
Sheets("Red Alerts").Range("A5:M500").ClearContents
If Sheets("General Areas Sauce").Cells("D20:D59").Value = "R" Then
Sheets("General Areas Sauce").Cells("G20:G59").cellcopy Destination:=Sheets("Red Alerts").Range("F5" & Rows.Count).Offset(1)
End If
End Sub
 
Try this:

This scripts assumes your sheets are named "Sheet 1" and "Sheet 1" with the space like you showed in your post. And it will search all the way down Column "B" looking for "R" and not just B2 to B4 like you said in your post I think this was a mistake on your part.

In one place you said:
then placed onto "Sheet 2 and Sheet 1"
and another place you said sheet Report I used sheet 1 and sheet 2

Code:
Sub Test()
Application.ScreenUpdating = False
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrowa = Sheets("Sheet 2").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrow = Sheets("Sheet 1").Cells(Rows.Count, "B").End(xlUp).Row + 1
Dim c As Range
Sheets("Sheet 1").Activate
    For Each c In Sheets("Sheet 1").Range("B2:B" & Lastrow)
        If c.Value = "R" Then
            c.Offset(0, 3).Copy Destination:=Sheets("Sheet 2").Range("A" & Lastrowa)
            Lastrowa = Lastrowa + 1
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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