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

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
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,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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