June 1, 2020
I will explain what I am trying to do. On the active sheet that I am running the macro on, there are 2 potential cells that I want pasted on the sheet "Shipping Dept". These active sheet cells are K5 and L5. K5 is considered the packing number and is calculated by a formula depending on numbers that are assigned to each row in the Shipping Dept sheet. This calculation is also dependent on which rows on Shipping Dept are visible because of filters. Provided this information, I have 3 situations that I want and I thought this code could achieve it, but I keep getting an "for control variable already in use" error. As seen below, each designated column is assigned to names called check1, check2, etc... I want K5 to be copy and pasted on the designated column for the visible rows through these situations....
1) It looks through each cell in check1 first. If that visible cell is empty, paste K5 on there.
2) If there has already been a Packing # put on there and it is the SAME, then I want to copy and paste L5 (L5 is from active sheet, not Shipping Dept) onto that cell.
3) If the cell already has a Packing # but it is not the same, I want it placed on that same row but for the column of check2.
... check 2 has to run through these same conditions though... and so on all the way to check5. If that specific row is filled in all columns up to check 5, there should be an error.
Other than the error, I thought I wrote my code correctly. Turns out it did not work. Please help. Here is my code:
ActiveSheet.Range("K5").Select
Selection.Copy
Sheets("Shipping Dept").Select
Set check1 = Range("Q2:Q6402").SpecialCells(xlCellTypeVisible)
Set check2 = Range("U2:U6402").SpecialCells(xlCellTypeVisible)
Set check3 = Range("Y2:Y6402").SpecialCells(xlCellTypeVisible)
Set check4 = Range("AC2:AC6402").SpecialCells(xlCellTypeVisible)
Set check5 = Range("AG2:AG6402").SpecialCells(xlCellTypeVisible)
For Each cell In check1
If cell = "" Then
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell = Sheets("Enerflex Shipping Ticket").Range("K5") Then
Sheets("Enerflex Shipping Ticket").Range("L5").Select
Selection.Copy
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell <> "" And cell <> Sheets("Enerflex Shipping Ticket").Range("K5") Then
'How do I say paste on same row but PL #2 column, but once it does this, it has to check the same if's..?
For Each cell In check2
If cell = "" Then
Sheets("Shipping Dept").Select
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell = Sheets("Enerflex Shipping Ticket").Range("K5") Then
Sheets("Enerflex Shipping Ticket").Range("L5").Select
Selection.Copy
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell <> "" And cell <> Sheets("Enerflex Shipping Ticket").Range("K5") Then
For Each cell In check3
If cell = "" Then
Sheets("Shipping Dept").Select
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell = Sheets("Enerflex Shipping Ticket").Range("K5") Then
Sheets("Enerflex Shipping Ticket").Range("L5").Select
Selection.Copy
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell <> "" And cell <> Sheets("Enerflex Shipping Ticket").Range("K5") Then
For Each cell In check4
If cell = "" Then
Sheets("Shipping Dept").Select
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell = Sheets("Enerflex Shipping Ticket").Range("K5") Then
Sheets("Enerflex Shipping Ticket").Range("L5").Select
Selection.Copy
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell <> "" And cell <> Sheets("Enerflex Shipping Ticket").Range("K5") Then
For Each cell In check5
If cell = "" Then
Sheets("Shipping Dept").Select
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell = Sheets("Enerflex Shipping Ticket").Range("K5") Then
Sheets("Enerflex Shipping Ticket").Range("L5").Select
Selection.Copy
MsgBox "Warning. There is already shipment date(s) for past shipment(s). You may proceed."
cell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ElseIf cell <> "" And cell <> Sheets("Enerflex Shipping Ticket").Range("K5") Then
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
October 5, 2010
Hi Carlos,
https://www.myonlinetraininghu.....this-first
Please post your workbook so we don't have to recreate it.
Regards
Phil
1 Guest(s)