Copy to other sheet cannot debug

yhtan0404

New Member
Joined
Mar 18, 2016
Messages
17
Hi can anyone help me check what's wrong with this code?

Sub copyTodifferentsheet()

Dim i As Integer
Dim Priority As String
Dim Task As Range

i = Sheets(1).Range("A4").Value


Do While i <= Sheets(1).Range("A4").End(xlDown).Value

Set Task = Sheets(1).Range("b3").Offset(i, 2)
Priority = Task.Value

If Priority = "Urgent" Then
Range(Task, Task.Offset(0, 1)).Copy
Sheets(2).Range(Cells(i + 1, 2), Cells(i + 1, 3)).PasteSpecial xlPasteValues


ElseIf Priority = "Important" Then
Range(Task, Task.Offset(0, 1)).Copy
Sheets(3).Range(Cells(i + 1, 2), Cells(i + 1, 3)).PasteSpecial xlPasteValues

ElseIf Priority = "Easy easy" Then
Range(Task, Task.Offset(0, 1)).Copy
Sheets(4).Range(Cells(i + 1, 2), Cells(i + 1, 3)).PasteSpecial xlPasteValues

Else
End If

i = i + 1

Loop

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
What happens when you try to run the code? If you get an error message, what's the message and what line is highlighted?
 
Upvote 0
I do not like reading code that does not do what you want.
Tell me in detail what your wanting to do.
Give me sheet names criteria and column numbers and any other details you have.
And I will try to help you.
 
Upvote 0
Does this work?
Code:
Sub copyTodifferentsheet()
Dim Task As Range
Dim Priority As String
Dim i As Long

    i = Sheets(1).Range("A4").Value

    Do While i <= Sheets(1).Range("A4").End(xlDown).Value

        Set Task = Sheets(1).Range("b3").Offset(i, 2)
        Priority = Task.Value

        If Priority = "Urgent" Then
            Range(Task, Task.Offset(0, 1)).Copy
            Sheets(2).Cells(i + 1, 2).PasteSpecial xlPasteValues

        ElseIf Priority = "Important" Then
            Range(Task, Task.Offset(0, 1)).Copy
            Sheets(3).Cells(i + 1, 2).PasteSpecial xlPasteValues

        ElseIf Priority = "Easy easy" Then
            Range(Task, Task.Offset(0, 1)).Copy
            Sheets(4).Cells(i + 1, 2).PasteSpecial xlPasteValues

        End If

        i = i + 1

    Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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