Macro help..can this be done??

JKast

New Member
Joined
Jul 26, 2011
Messages
21
Can anyone tell me how I can make this code work? The first IF statement always works, but the second one never copies the data to the other sheet. Any help is appreciated!

Sub CopyData()
Dim i As Long

For i = 2 To 5000 'change numbers to the range of rows you are checking
If Range("g" & i) = "ACME DISTRIBUTION" Then
Range("g" & i).EntireRow.Copy _
Destination:=Sheets("Acme Distribution").Range("A65536").End(xlUp).Offset(1, 0)

End If
Next
For i = 2 To 5000
If Range("g" & i) = "cycle logistics" Then
Range("g" & i).EntireRow.Copy _
Destination:=Sheets("Cycle Logistics").Range("A65536").End(xlUp).Offset(1, 0)
End If
Next
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Is it a problem with upper/lower case not matching?

If so, head your module with the compiler directive Option Compare Text. This will make all your text comparisons non-case-sensitive.

If not, place a breakpoint at the second IF statement and examine the value in Range("g" & i), then compare it carefully with that character string - maybe there's a trailing blank in the cell?

Step through the code using the F8 key to check where it's actually going.
 
Last edited:
Upvote 0
VBA is case sensitive...

Try

If Ucase(Range("g" & i)) = "ACME DISTRIBUTION" Then

and

If Ucase(Range("g" & i)) = "CYCLE LOGISTICS" Then
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,472
Members
452,915
Latest member
hannnahheileen

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