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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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