Please Help With Easy VBA??

Craigeeh22

New Member
Joined
Sep 11, 2008
Messages
15
Hi
I have a quick easy question i have this code which works fine on my worksheet but i need it to look down the whole Coloum of R(i have highlighted below) at the moment it looks down the list and as soon as there is a gap it stops?? for example
ColoumR
Complete
Complete This will copy to other worksheet
Complete

Complete these wont copy due to gap????
Complete



Sub MoveRows()
Dim rngOrigin As Range, rngDest As Range
Dim i, j As Integer

i = 1: j = 1
Set rngOrigin = Sheets("Sheet1").Range("R2")
Set rngDest = Sheets("Sheet2").Range("A1").Offset(Application.WorksheetFunction.CountA(Sheets("Sheet2").Range("A:A")))

Do While rngOrigin.Offset(i, 0).Value <> ""
If rngOrigin.Offset(i, 0).Value = "Complete" Then
rngOrigin.Offset(i, 0).EntireRow.Copy
Sheets("Sheet2").Activate
rngDest.Offset(j, 0).Select
ActiveSheet.Paste
Sheets("Sheet1").Activate
rngOrigin.Offset(i, 0).EntireRow.Delete xlShiftUp
j = j + 1
i = i - 1
End If
i = i + 1
Loop
Application.CutCopyMode = False
End Sub

Thank you if you can help??
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
Sub MoveRows()
Dim rngOrigin As Range, rngDest As Range
Dim i, j As Integer
Dim LastRow As Long

    i = 1: j = 1
    Set rngOrigin = Sheets("Sheet1").Range("R2")
    With Sheets("Sheet2")
    
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    
        For i = LastRow To 2 Step -1
          
            If Sheets("Sheet1").Range("R2").Value = "Complete" Then
                Sheets("Sheet1").Rows(i).Copy .Range("A1").Offset(j, 0)
                Sheets("Sheet1").Rows(i).Delete
                j = j + 1
            End If
        Loop
    End With
    
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Hi i got a msg when i did your code it said:
:confused:
Compile error
loop without Do?

and wont work???

can this be changed?

Thank you for quick response.
:)
 
Upvote 0
I think xld must have tried a couple different methods to do the loop, and ended up with a mixture of both....

The word "Loop" should be changed to "Next"

Interesting that the error was "Loop Without Do" and Not "For without Next"

I would think logically it would have been the other way around, since it gets to the For line before it get's to the Loop line...
 
Upvote 0
Thanks Jonmo but when i put next in it doesnt do anything and isnt searching the Coloum R for the word Complete??

Its not going well so far!! :mad:
 
Upvote 0
I didn't read the code to see what it was doing, I just saw the error...

perhaps this line

If Sheets("Sheet1").Range("R2").Value = "Complete" Then

should be changed to

If Sheets("Sheet1").Range("R" & i).Value = "Complete" Then
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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