So I am just trying to create a copy and paste function. I want it to be a bit more dynamic than some of the similar problems I have seen on here. When I get to the line (code below) "set rng = ws.Range(Cells(i, 7), Cells(i, 12))" I get the error 1004 Application-defined or object defined error. Also the button is in the sheet named "Forms".
I originally didn't have " set rng = ws." before Range(Cells(i, 7), Cells(i, 12)) and I didn't get an error but It would copy data from "forms" rather than from "Goals". Because of how the excel spreadsheet is formatted the numbers in the function are correct, I believe (not sure if that is relevant).
Ultimately, I am trying to get the error to go away, and to get it to work properly. Any help or suggestions welcome.
Private Sub CommandButton1_Click()
Dim rng As Range
Dim ws As Worksheet
Set ws = Worksheets("Goals")
a = Worksheets("Goals").Cells(Rows.Count, 7).End(xlUp).Row
For i = 2 To a
If Worksheets("Goals").Cells(i, 20).Value = "Red" Then
ws.Activate
Set rng = ws.Range(Cells(i, 7), Cells(i, 12))
rng.Copy
Worksheets("Scorecard").Activate
b = Worksheets("Scorecard").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Scorecard").Cells(b + 1, 2).Select
ActiveSheet.Paste
Worksheets("Goals").Activate
End If
Next
Application.CutCopyMode = False
End Sub