Copy specific excel data to another excel workbook with condition.

Xlacs

Board Regular
Joined
Mar 31, 2021
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am kinda new to this VBA programming so I am wondering if someone could help me with this simple problem.
So I have a time and motion study tracker with start, end and submit button button. I managed to worked on start and end.
But I am struggling to submit an specific data to my masterfile. In my workbook. I have a dropdown selection of status.. If the value of the dropdown is Pending, then those cases should be submitted in my Archive workbook when I hit the Submit button and the status in my last column will be updated to Submitted. So it will exclude those cases on my next submission and should not overlap the data in master file.

Please.. Someone help me on this. =(

VBA Code:
Sub Submit()

Dim STunsent As String
Dim OA As Object
Dim msg As Object
Dim sh As Worksheet


Dim Outapp As Object, Logfile As String

Dim r As Long, lr As Long, Archive As Workbook


sh = ThisWorkbook.Sheets("Prod")

Dim x As Integer
Dim lastrow As Integer

lastrow = Application.WorksheetFunction.CountBlank(sh.Range("D:D"))

For x = 2 To lastrow

If sh.Range("O" & i).Value <> "Submitted" And sh.Range("J" & i).Value = "Pending" Then

Set Archive = Workbooks.Open("C:\Users\ChrisLacs\Desktop\Test\Archive.xlsm")
r = 2

lr = Cells(Rows.Count, 1).End(xlUp).Row
Range(Cells(r, 1), Cells(r, 3)).Copy
Active.Paste Destination:=Archive.Worksheets("Master").Rows(erow)

sh.Range("O" & i).Value = "Submitted"


End If

r = r + 1


Archive.Close

Next
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
A gentle reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,479
Messages
6,125,043
Members
449,206
Latest member
Healthydogs

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