# I don't know what I'm doing!

#### Jon von der Heyden

##### MrExcel MVP, Moderator
Hi,

I've written the following code:

Code:
``````Sub Simulate()

Application.Calculation = xlCalculationManual

Dim c As Range

For i = 1 To 675

For Each c In Range("rng")
If c.Value = Range("tgt").Value Then
Rows(c).Copy

End If
Next c
Calculate

Next

Application.Calculation = xlCalculationAutomatic

End Sub``````

Basically, all I want is to copy the row when c.value = tgt, but it doesn't like the syntax I'm trying. Once copied I want to move it to a sheet called "output" and paste to the next empty row (but I should be fine with this piece of code).

Cheers,
Jon

### Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You have your variables in quotes.

Sub Simulate()

Application.Calculation = xlCalculationManual

Dim c As Range

For i = 1 To 675

For Each c In Range("rng")
If c.Value = Range("tgt").Value Then
Rows(c).Copy

End If
Next c
Calculate

Next

Application.Calculation = xlCalculationAutomatic

End Sub

I'm not sure what the 1 to 675 is for.

And, you weren't pasting your data anywhere.

Try:

Sub Simulate()

Application.Calculation = xlCalculationManual

Dim c As Range

For Each c In Range("rng")
If c.Value = Range("tgt").Value Then
c.EntireRow.Copy Sheets("output").Range("A65536").End(xlUp).Offset(1, 0)
End If
Next c
Calculate

Application.Calculation = xlCalculationAutomatic

End Sub

rng & tgt need to be Named Ranges on your sheet or you need to Set these ranges or define there location limits.

Do you have these Ranges Named Using: Toolbar: Insert - Name Define...?

Thanks all of you, got this solved now. I wasn't clear, but yes "tgt" and "rng" are defined range names (i.e. Insert->Names->Define).

I think that the problem was with the row selection syntax, works with EntireRow.Copy.

Thanks again...

Replies
1
Views
349
Replies
5
Views
300
Replies
1
Views
201
Replies
3
Views
142
Replies
3
Views
429

1,203,348
Messages
6,054,885
Members
444,760
Latest member
TeckTeck

### 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.

### Which adblocker are you using?

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

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