I am trying to create a paste loop and want the loop to continue as long as the values within the column are negative and paste it to another workbook that the user will select. Also, I need to paste one range first before pasting another. And in the new workbook, I need to start pasting one cell down once it is finished with the 4oz loop to start with the 8oz loop.
Sub Absolute_Value() ' ' Absolute_Value Macro 'Defining Terms
Dim sht As Worksheet
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim sht3 As Worksheet
Dim nwbsht1 As Worksheet
Dim nwbsht2 As Worksheet
Dim nwbsht3 As Worksheet
Dim nwbsht4 As Worksheet
Dim nwbsht5 As Worksheet
Dim nwbsht6 As Worksheet
Dim nwbsht7 As Worksheet
Dim nwbsht8 As Worksheet
Dim rngToAbs As Range
Dim c As Range
Dim wb As Workbook
Dim nwb As Workbook
Dim Onhand As Range
Dim OnHand2 As Range
Dim OnHand1 As Range
Dim OnHand3 As Range
Dim Pallet As Range
Dim PalletType As Range
Dim Item As Range
Dim Item2 As Range
Dim UnitQty As Range
Dim CL As Range
Dim DL As Range
Dim OutputArray
Dim I As Long
'Setting ranges for PackPlan workbook
Set wb = Application.ActiveWorkbook
With ActiveWorkbook.Worksheets("Arils Pack Plan ")
Set rngToAbs = .Range("F7:F28")
Set Item = .Range("B7:B" & .Cells(.Rows.Count, "B").End(xlUp).Row)
Set PalletType = .Range("E7:E" & .Cells(.Rows.Count, "E").End(xlUp).Row)
End With
'Opening Recent ATS report
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"
.AllowMultiSelect = False
.Show
Application.Workbooks.Open .SelectedItems(1)
Set nwb = Application.ActiveWorkbook
End With
'Setting Ranges for Daily Need Worksheet
'4oz Range Setting
Set nwb = Application.ActiveWorkbook
Set nwbsht1 = nwb.Sheets("DAILY NEED (DR)")
Set Onhand = nwbsht1.Range("Q5:Q14")
Set nwb = Application.ActiveWorkbook
Set nwbsht2 = nwb.Sheets("DAILY NEED (DR)")
Set Pallet = nwbsht2.Range("E5:E14")
Set nwb = Application.ActiveWorkbook
Set nwbsht3 = nwb.Sheets("DAILY NEED (DR)")
Set OnHand1 = nwbsht3.Range("U5:U14")
Set nwb = Application.ActiveWorkbook
Set nwbsht4 = nwb.Sheets("DAILY NEED (DR)")
Set OnHand2 = nwbsht4.Range("Y5:Y14")
'8oz Range Setting
Set nwb = Application.ActiveWorkbook
Set nwbsht5 = nwb.Sheets("DAILY NEED (DR)")
Set OnHand3 = nwbsht5.Range("Q15:Q25")
Set nwb = Application.ActiveWorkbook
Set nwbsht6 = nwb.Sheets("DAILY NEED (DR)")
Set Pallet = nwbsht6.Range("E15:E25")
Set nwb = Application.ActiveWorkbook
Set nwbsht7 = nwb.Sheets("DAILY NEED (DR)")
Set OnHand1 = nwbsht7.Range("T15:T25")
Set nwb = Application.ActiveWorkbook
Set nwbsht8 = nwb.Sheets("DAILY NEED (DR)")
Set OnHand2 = nwbsht8.Range("Y15:Y25")
'Copy and Paste Loop for Units
nwb.Activate
I = 1
ReDim OutputArray(1 To Onhand.Cells.Count)
For Each CL In Onhand.Cells
If CL.Value < 0 Then
OutputArray(I) = CL.Value
I = I + 1
End If
Next CL
wb.Activate
wb.Sheets("Arils Pack Plan ").Range("F7").Resize(I, 1) = Application.Transpose(OutputArray)
nwb.Activate
ReDim OutputArray(1 To OnHand1.Cells.Count)
For Each DL In OnHand1.Cells
If DL.Value < 0 Then
OutputArray(I) = DL.Value
I = I + 1
End If
Next DL
wb.Activate
wb.Sheets("Arils Pack Plan ").Range("F7").Resize(I, 1) = Application.Transpose(OutputArray)