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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

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