VBA copy row to different sheets when different criteria are met

mychi11

Board Regular
Joined
May 11, 2020
Messages
95
Office Version
  1. 2016
Platform
  1. Windows
Dear all,

I'd like to copy data from "Data Pur" to two different sheets ie the Master(Pur) and Fix Asset+Eva when column 7 >0 and column 6 =2, then clear the content in the Data Pur after that. but it appears that the subscript is out of range. Wonder if anyone can help.

Sub Copyrowfromdatainputtopurchase()

Sheets("Master(Pur)").Unprotect

Sheets("Data Pur").Select

Range("A2:K25").Copy


Sheets(".").Select

Range("A2").Select


ActiveSheet.Paste


Application.CutCopyMode = False


'
' autofitPO Macro
'

'
Rows("2:21").Select
Selection.Rows.AutoFit



a = Worksheets("Data Pur").Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To a

If Worksheets("Data Pur").Cells(i, 7).Value > "0" Then
Worksheets("Data Pur").Rows(i).Copy
Worksheets("Master(Pur)").Activate
c = Worksheets("Master(Pur)").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Master(Pur)").Cells(c + 1, 1).Select

ElseIf Worksheets("Data Pur").Cells(i, 6).Value > 2 Then
Worksheets("Data Pur").Rows(i).Copy
Worksheets("Fix Assets+Eva").Activate
d = Worksheets("Fix Assets+Eva)").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Fix Assets+Eva").Cells(d + 1, 1).Select
ActiveCell.PasteSpecial Paste:=xlValues, operation:=xlPasteSpecialOperationNone
Worksheets("Data Pur").Activate


End If
Next
Application.CutCopyMode = False

ThisWorkbook.Worksheets("Data Pur").Cells(1, 1).Select



Worksheets("Data Pur").Range("A2:K24").SpecialCells(xlCellTypeConstants).ClearContents

Sheets("Master(Pur)").Protect

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Should the red ) be there?
Rich (BB code):
d = Worksheets("Fix Assets+Eva)").Cells(Rows.Count, 1).End(xlUp).Row
 
Upvote 0
Thanks noted on that. There's still some other problems with the code
 
Upvote 0
It would help a bit if you told us what line you are getting the error on.
 
Upvote 0
You still haven't stated on what line the error is occurring.
 
Upvote 0
d = Worksheets("Fix Assets+Eva)").Cells(Rows.Count, 1).End(xlUp).Row
there is a run time error 1004
 
Upvote 0
As I stated in my previous post there is an extra closing bracket in comparison to your other line referring to the same sheet. It is still there in your last post.
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

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