Hi fredfarmer,
As far as the dropdown, I also assume you can remove that? (Data tab, drop down data validation, select data validation, change the "Allow" box to "any value".
This code will ask if the user wants to create a new AFR and then ask for a password if yes is chosen:
Sub PopulateForm()
With ThisWorkbook
Dim myPass As String: myPass = "password"
Dim myPassRequest As String
Dim myAnswer As Integer
Dim rng As Range
Dim rng2 As Range
Dim i As Integer
Dim wsSrc1 As Worksheet: Set wsSrc1 = .Sheets("AFRsDB")
Dim wsSrc2 As Worksheet: Set wsSrc2 = .Sheets("AFRsParts")
Dim wsTar As Worksheet: Set wsTar = .Sheets("AFRsInput")
Dim lngAFR As Long: lngAFR = wsTar.Range("F2").Value
Dim lngRow As Long
Dim lngSrc2LR As Long
Dim NewTblRow As ListRow
Set rng = wsSrc1.Range("C:C").Find(lngAFR, , xlValues, xlWhole)
If Not rng Is Nothing Then
lngRow = rng.Row
For i = 3 To 37
Set rng2 = wsTar.Range("B4:J19").Find(wsSrc1.Cells(1, i).Value)
rng2.Offset(0, 2) = wsSrc1.Cells(lngRow, i)
Next i
On Error Resume Next
wsTar.ListObjects("Table1").DataBodyRange.Delete
On Error GoTo 0
With wsSrc2
lngSrc2LR = .Cells(Rows.Count, "A").End(xlUp).Row
For i = 3 To lngSrc2LR
If .Cells(i, "C") = lngAFR Then
Set NewTblRow = wsTar.ListObjects("Table1").ListRows.Add
NewTblRow.Range(1) = .Cells(i, "C")
NewTblRow.Range(2) = .Cells(i, "D")
NewTblRow.Range(3) = .Cells(i, "E")
NewTblRow.Range(4) = .Cells(i, "F")
End If
Next i
End With
Else
If Worksheets("AFRsInput").Range("F2").Value = vbNullString Then Exit Sub
myAnswer = MsgBox("Are you sure you want to add this new AFR#?", vbYesNo)
If myAnswer <> vbYes Then Exit Sub
myPassRequest = InputBox("Please enter the password to verify the new AFR #")
If myPassRequest <> myPass Then
MsgBox ("Sorry, that password is incorrect")
Worksheets("AFRsInput").Range("F2").Value = vbNullString
Exit Sub
Else
MsgBox ("New AFR # accepted.")
End If
End If
End With
End Sub
Bookmarks