All, I am working on creating a vba code that saves data on a form with a click of a button. I have the code worked out but currently it takes too long to submit so I am working on trying to shorten it up. This is a snippet of the original code.
Sub TransferDeliveryInfoB13()
Sheets("Parts In-Out Form").Select
Range("d9").Select
If ActiveCell.Value = ("In") And (Sheets("Parts In-Out Form").Range("b13") > 0) Then
'Copy Part Number'
Dim LastRow As Long
LastRow = Sheets("Deliveries").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
Sheets("Parts In-Out Form").Range("b13").Copy
Sheets("Deliveries").Cells(LastRow, 3).PasteSpecial xlPasteValues
'Copy Back Ordered Quanity'
Sheets("Parts In-Out Form").Range("c13").Copy
Sheets("Deliveries").Cells(LastRow, 9).PasteSpecial xlPasteValues
'Copy Back Order ETA
Sheets("Parts In-Out Form").Range("c9").Copy
Sheets("Deliveries").Cells(LastRow, 10).PasteSpecial xlPasteValues
'Copy Quanity'
Sheets("Parts In-Out Form").Range("d13").Copy
Sheets("Deliveries").Cells(LastRow, 4).PasteSpecial xlPasteValues
'Copy Employee Number
Sheets("Parts In-Out Form").Range("f9").Copy
Sheets("Deliveries").Cells(LastRow, 5).PasteSpecial xlPasteValues
'Copy BOL Number
Sheets("Parts In-Out Form").Range("h9").Copy
Sheets("Deliveries").Cells(LastRow, 2).PasteSpecial xlPasteValues
'Copy PO Number
Sheets("Parts In-Out Form").Range("f12").Copy
Sheets("Deliveries").Cells(LastRow, 8).PasteSpecial xlPasteValues
'Copying Whether or Not Back Order Delivery
Sheets("Parts In-Out Form").Range("h12").Copy
Sheets("Deliveries").Cells(LastRow, 12).PasteSpecial xlPasteValues
'Copying Date
Sheets("Parts In-Out Form").Range("b9").Copy
Sheets("Deliveries").Cells(LastRow, 1).PasteSpecial xlPasteValues
Call TransferDeliveryInfoB14
Else
Sheets("Deliveries").Select
ActiveSheet.Protect ("mustache")
Sheets("Parts In-Out Form").Range("B9,D9,F9,H9,C9,F12,B12:B42,C12:C42,D12:D42,H12").ClearContents
End If
End Sub
Sub TransferDeliveryInfoB14()
Sheets("Parts In-Out Form").Select
Range("d9").Select
If ActiveCell.Value = ("In") And (Sheets("Parts In-Out Form").Range("b14") > 0) Then
'Copy Part Number'
Dim LastRow As Long
LastRow = Sheets("Deliveries").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
Sheets("Parts In-Out Form").Range("b14").Copy
Sheets("Deliveries").Cells(LastRow, 3).PasteSpecial xlPasteValues
'Copy Back Ordered Quanity'
Sheets("Parts In-Out Form").Range("c14").Copy
Sheets("Deliveries").Cells(LastRow, 9).PasteSpecial xlPasteValues
'Copy Back Order ETA
Sheets("Parts In-Out Form").Range("c9").Copy
Sheets("Deliveries").Cells(LastRow, 10).PasteSpecial xlPasteValues
'Copy Quanity'
Sheets("Parts In-Out Form").Range("d14").Copy
Sheets("Deliveries").Cells(LastRow, 4).PasteSpecial xlPasteValues
'Copy Employee Number
Sheets("Parts In-Out Form").Range("f9").Copy
Sheets("Deliveries").Cells(LastRow, 5).PasteSpecial xlPasteValues
'Copy BOL Number
Sheets("Parts In-Out Form").Range("h9").Copy
Sheets("Deliveries").Cells(LastRow, 2).PasteSpecial xlPasteValues
'Copy PO Number
Sheets("Parts In-Out Form").Range("f12").Copy
Sheets("Deliveries").Cells(LastRow, 8).PasteSpecial xlPasteValues
'Copying Whether or Not Back Order Delivery
Sheets("Parts In-Out Form").Range("h12").Copy
Sheets("Deliveries").Cells(LastRow, 12).PasteSpecial xlPasteValues
'Copying Date
Sheets("Parts In-Out Form").Range("b9").Copy
Sheets("Deliveries").Cells(LastRow, 1).PasteSpecial xlPasteValues
Call TransferDeliveryInfoB15
Else
Sheets("Deliveries").Select
ActiveSheet.Protect ("mustache")
Sheets("Parts In-Out Form").Range("B9,D9,F9,H9,C9,F12,B12:B42,C12:C42,D12:D42,H12").ClearContents
End If
End Sub
What I am attempting to do is instead of a million if then statements for each cell to compact that into one code where it will copy and paste the parts number, and quanity. and if there is there a value it will copy the bol, date, employee number in the corresponding column in the row. here's what I have so far.
Sub TransferDeliveryInfoB12()
'make sure to unlock sheet
Sheets("Deliveries").Select
ActiveSheet.Unprotect ("mustache")
Sheets("Parts In-Out Form").Select
Range("d9").Select
If ActiveCell.Value = ("In") Then
Dim LastRow As Long
LastRow = Sheets("Deliveries").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
'Copy Parts Number
Sheets("Parts In-Out Form").Range("b12:b42").Copy
Sheets("Deliveries").Cells(LastRow, 3).PasteSpecial xlPasteValues
'Copy Back Ordered Quanity
Sheets("Parts In-Out Form").Range("c12:c42").Copy
Sheets("Deliveries").Cells(LastRow, 9).PasteSpecial xlPasteValues
'Copy Parts Quanity
Sheets("Parts In-Out Form").Range("b12:b42").Copy
Sheets("Deliveries").Cells(LastRow, 4).PasteSpecial xlPasteValues
I am not really sure where to go from this point. Thanks in advance for all direction and help given.