Good afternoon!
I have a macro that populates data from a UserForm to an intermediate sheet (called JobGrid) then creates a new row on the main sheet (called Calendar). It then copies the data from JobGrid to the new row on the main sheet.
Works great. What I now need is to scan a range on the Calendar sheet (called SubLotColumn) before adding the job to see if it already exists. If it exists you'd get a message box saying so and the Sub ends. If it doesn't exist it goes ahead (starting at 'Insert Blank Row).
Here's my fabulous (probably over-engineered) code:
I have a macro that populates data from a UserForm to an intermediate sheet (called JobGrid) then creates a new row on the main sheet (called Calendar). It then copies the data from JobGrid to the new row on the main sheet.
Works great. What I now need is to scan a range on the Calendar sheet (called SubLotColumn) before adding the job to see if it already exists. If it exists you'd get a message box saying so and the Sub ends. If it doesn't exist it goes ahead (starting at 'Insert Blank Row).
Here's my fabulous (probably over-engineered) code:
VBA Code:
Sub SubmitJob()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sh As Worksheet
Dim iRow As Long
'Populate JobGrid
Set sh = ThisWorkbook.Sheets("JobGrid")
With sh
.Cells(1) = frmForm.ShippingDate.Value
.Cells(2) = frmForm.SubCode.Value
.Cells(3) = frmForm.SubName.Value
.Cells(4) = frmForm.LotNumber.Value
.Cells(5) = frmForm.Models.Value
.Cells(6) = frmForm.Elevation.Value
.Cells(7) = frmForm.GarageHandling.Value
.Cells(10) = Application.UserName
.Cells(11) = [Text(Now(), "MM/DD/YYYY HH:MM:SS AM/PM")]
End With
'Insert Blank Row
Sheets("Calendar").Select
ActiveSheet.Unprotect
Sheets("Template").Visible = True
Sheets("Template").Select
Rows("5:5").Select
Selection.Copy
Sheets("Calendar").Select
Rows("10:10").Select
Selection.Insert Shift:=xlDown
Rows(ActiveCell.Row).Select
'Copy Shipping Date
Sheets("JobGrid").Visible = True
Sheets("JobGrid").Select
Range("A1").Select
Selection.Copy
Sheets("Calendar").Select
Range("B10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy Subdivision/Lot Number
Sheets("JobGrid").Select
Range("I1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Calendar").Select
Range("C10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy Model
Sheets("JobGrid").Select
Range("E1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Calendar").Select
Range("F10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy Elevation
Sheets("JobGrid").Select
Range("F1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Calendar").Select
Range("G10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy Garage Handling
Sheets("JobGrid").Select
Range("G1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Calendar").Select
Range("H10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy Added By
Sheets("JobGrid").Select
Range("J1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Calendar").Select
Range("BQ10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy Date/Time Added
Sheets("JobGrid").Select
Range("K1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Calendar").Select
Range("BR10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub