Copy / Paste Syntax?

Alfred12

New Member
Joined
Feb 28, 2011
Messages
15
I would love some guidance on how to fix my copy and paste code in the sub that I have pasted below. I know I am probably overlooking something obvious, but I haven't been able to crack it on my own. Any help would be greatly appreciated.

What I am trying to do here is look through each row on each sheet in a workbook. If the value in column D is 1 AND the value in column E is yes, I want to copy the text in column A to the next free row on the top worksheet (sheet 1).

Some of this works, and some doesn't. I think that it is reliably finding the 1s in column D. I fear it may not be finding the "yes"s in column E. And in some cases it is copying the right text from column A, but it has never once pasted that text to the top sheet.

Thanks in advance!

[FONT=&quot]Sub Compile()[/FONT]
[FONT=&quot] Dim S As Integer[/FONT]
[FONT=&quot] Dim i As Integer[/FONT]
[FONT=&quot] For S = 2 To Sheets.Count[/FONT]
[FONT=&quot] Worksheets(S).Activate[/FONT]
[FONT=&quot] For i = 1 To 5[/FONT]
[FONT=&quot] If Worksheets(S).Cells(i, 4).Value = 1 Then[/FONT]
[FONT=&quot] MsgBox "Found a 1!"[/FONT]
[FONT=&quot] If Worksheets(S).Cells(i, 5).Value = yes Then[/FONT]
[FONT=&quot] MsgBox "Found a yes!"[/FONT]
[FONT=&quot] Worksheets(S).Cells(i, 1).Copy[/FONT]
[FONT=&quot] Worksheets(1).Range("A250").End(x1Up).Offset(1, 0).Paste[/FONT]
[FONT=&quot] MsgBox "Got Here"[/FONT]
[FONT=&quot] End If[/FONT]
[FONT=&quot] End If[/FONT]
[FONT=&quot] Next i[/FONT]
[FONT=&quot] Next S[/FONT]
[FONT=&quot]End Sub[/FONT]
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I would love some guidance on how to fix my copy and paste code in the sub that I have pasted below. I know I am probably overlooking something obvious, but I haven't been able to crack it on my own. Any help would be greatly appreciated.

What I am trying to do here is look through each row on each sheet in a workbook. If the value in column D is 1 AND the value in column E is yes, I want to copy the text in column A to the next free row on the top worksheet (sheet 1).

Some of this works, and some doesn't. I think that it is reliably finding the 1s in column D. I fear it may not be finding the "yes"s in column E. And in some cases it is copying the right text from column A, but it has never once pasted that text to the top sheet.

Thanks in advance!

[FONT=&quot]Sub Compile()[/FONT]
[FONT=&quot] Dim S As Integer[/FONT]
[FONT=&quot] Dim i As Integer[/FONT]
[FONT=&quot] For S = 2 To Sheets.Count[/FONT]
[FONT=&quot] Worksheets(S).Activate[/FONT]
[FONT=&quot] For i = 1 To 5[/FONT]
[FONT=&quot] If Worksheets(S).Cells(i, 4).Value = 1 Then[/FONT]
[FONT=&quot] MsgBox "Found a 1!"[/FONT]
[FONT=&quot] If Worksheets(S).Cells(i, 5).Value = yes Then[/FONT]
[FONT=&quot] MsgBox "Found a yes!"[/FONT]
[FONT=&quot] Worksheets(S).Cells(i, 1).Copy[/FONT]
[FONT=&quot] Worksheets(1).Range("A250").End(x1Up).Offset(1, 0).Paste[/FONT]
[FONT=&quot] MsgBox "Got Here"[/FONT]
[FONT=&quot] End If[/FONT]
[FONT=&quot] End If[/FONT]
[FONT=&quot] Next i[/FONT]
[FONT=&quot] Next S[/FONT]
[FONT=&quot]End Sub[/FONT]


Try changing this:

If Worksheets(S).Cells(i, 5).Value = yes Then

To this:

If Worksheets(S).Cells(i, 5).Value = "yes" Then
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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