VBA copy row to different sheets when different criteria are met

mychi11

Board Regular
Joined
May 11, 2020
Messages
82
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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Should the red ) be there?
Rich (BB code):
d = Worksheets("Fix Assets+Eva)").Cells(Rows.Count, 1).End(xlUp).Row
 

mychi11

Board Regular
Joined
May 11, 2020
Messages
82
Office Version
  1. 2016
Platform
  1. Windows
Thanks noted on that. There's still some other problems with the code
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
It would help a bit if you told us what line you are getting the error on.
 

mychi11

Board Regular
Joined
May 11, 2020
Messages
82
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

It would help a bit if you told us what line you are getting the error on.
There is a run time error "1004"
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
You still haven't stated on what line the error is occurring.
 

mychi11

Board Regular
Joined
May 11, 2020
Messages
82
Office Version
  1. 2016
Platform
  1. Windows
d = Worksheets("Fix Assets+Eva)").Cells(Rows.Count, 1).End(xlUp).Row
there is a run time error 1004
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,258
Messages
5,641,162
Members
417,195
Latest member
Vishal kumar

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
Top