Split data that fits criteria equally into 2 worksheets in another Excel file

meowsongg

New Member
Joined
Jul 20, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Dear all,

Rows in Workbook 1 that has column H, I, J or K filled up are ready for transfer.

I would like to copy and paste rows that are ready for transfer equally into 2 existing worksheets (Alex and IMHD) in Workbook 2.

Each worksheet in Workbook 2 requires different information to be copied over from Workbook 1. I have figured out the 2 different sets of copy and paste codes.

However, I am unable to find the code that can split the data such that half executes the 1st copy and paste code (CopytoAlex), while the other half executes the other copy and paste code (CopytoIM).

Note: Feel free to make any clarifications. I have tried my best to explain.

VBA Code:
Public Function CouriersTemplate()
Workbooks("Workbook 2.xlsb").Activate
Dim sourceColumn As Range, targetColumn As Range
Dim i As Integer, endrow As Integer, WB As Integer, RB As Integer, FI As Integer, CA As Integer, alexCounter As Integer, IMCounter As Integer
Dim alexDate As Date, deliveryDate As Date
Dim order As String

Application.ScreenUpdating = False

alexDate = courierDate("ALEX")
endrow = Workbooks("Workbook 1.xlsb").Worksheets("Masterlist").Cells(Rows.Count, 1).End(xlUp).Row
alexCounter = Workbooks("Workbook 2.xlsb").Worksheets("ALEX").Cells(Rows.Count, 2).End(xlUp).Row + 1
IMCounter = Workbooks("Workbook 2.xlsb").Worksheets("IMHD").Cells(Rows.Count, 2).End(xlUp).Row + 1

For i = endrow To 4 Step -1
 
 WB = Workbooks("Workbook 1.xlsb").Worksheets("Masterlist").Cells(i, 8)
 RB = Workbooks("Workbook 1.xlsb").Worksheets("Masterlist").Cells(i, 9)
 FI = Workbooks("Workbook 1.xlsb").Worksheets("Masterlist").Cells(i, 10)
 CA = Workbooks("Workbook 1.xlsb").Worksheets("Masterlist").Cells(i, 11)
 
 'Get delivery date
 deliveryDate = CDate(Workbooks("Workbook 1.xlsb").Worksheets("Masterlist").Cells(i, 6).Value)
 
 If (RB >= 1 Or WB >= 1 Or FI >= 1 Or CA >= 1) And deliveryDate = alexDate Then
 Call CopytoAlex(i, alexCounter, order)
 alexCounter = alexCounter + 1
 
 Next (RB >= 1 Or WB >= 1 Or FI >= 1 Or CA >= 1) And deliveryDate = alexDate Then
 Call CopytoIM(i, IMCounter, order)
 IMCounter = IMCounter + 1
 
 End If
 
Next i
End Function
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

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