Hi,
Having trouble with some VBA coding and can't figure out my error. I have a spreadsheet that users will need to filter based on selections they make then select a button to run the code. I added data validation lists in cells D2 and E2 that will give the options to filter the list (both conditions to be met. The VBA will filter the list and do a few other things like insert values, names, etc. There are approximately 18 combinations of criteria so I chose to do the filtering this way.
Below is the start of my code. I am getting a "Compile Error Else without If" error and I can't figure out my mistake. Below is the code so far which just has 3 of the possible combinations of criteria. The code gets hung up on the first "ElseIf" line ("ElseIf list1 = "Construction Contingency" And list2 = "Open" Then").
Any help would be appreciated.
Thanks!
Having trouble with some VBA coding and can't figure out my error. I have a spreadsheet that users will need to filter based on selections they make then select a button to run the code. I added data validation lists in cells D2 and E2 that will give the options to filter the list (both conditions to be met. The VBA will filter the list and do a few other things like insert values, names, etc. There are approximately 18 combinations of criteria so I chose to do the filtering this way.
Below is the start of my code. I am getting a "Compile Error Else without If" error and I can't figure out my mistake. Below is the code so far which just has 3 of the possible combinations of criteria. The code gets hung up on the first "ElseIf" line ("ElseIf list1 = "Construction Contingency" And list2 = "Open" Then").
Any help would be appreciated.
Thanks!
VBA Code:
Sub Button21_Click() 'filter Use Log control button by SOF and Status
ActiveSheet.Unprotect Password:="1234"
Dim list1 As String, list2 As String
list1 = Range("D2")
list2 = Range("E2")
If list1 = "Construction Contingency" And list2 = "Used" Then
With ActiveSheet.Range("A12:J1010")
.AutoFilter Field:=5, Criteria1:="Construction Contingency"
.AutoFilter Field:=6, Criteria2:="Closed"
Range("A7") = Sheets("ExposureLog").Range("I2:I2") & (" - ") & Range("D2") 'set for all transactions
Range("I6") = Sheets("Table").Range("E68") 'set for construction contingency
Range("I7") = Sheets("Table").Range("E69") 'set for construction contingency
Range("I8") = Sheets("Table").Range("E70") 'set for construction contingency
Range("A9") = Range("E2") & (" ") & ("CONTINGENCY TRANSACTIONS") 'set for all transactions - may need IF statement to add note that pending means open
ElseIf list1 = "Construction Contingency" And list2 = "Open" Then
With ActiveSheet.Range("A12:J1010")
.AutoFilter Field:=5, Criteria1:="Construction Contingency"
.AutoFilter Field:=6, Criteria2:="Open"
Range("A7") = Sheets("ExposureLog").Range("I2:I2") & (" - ") & Range("D2") 'set for all transactions
Range("I6") = Sheets("Table").Range("E68") 'set for construction contingency
Range("I7") = Sheets("Table").Range("E69") 'set for construction contingency
Range("I8") = Sheets("Table").Range("E70") 'set for construction contingency
Range("A9") = Range("E2") & (" ") & ("CONTINGENCY TRANSACTIONS") 'set for all transactions - may need IF statement to add note that pending means open
ElseIf list1 = "Construction Contingency" And list2 = "All" Then
With ActiveSheet.Range("A12:A1010")
.AutoFilter Field:=5, Criteria1:="Construction Contingency"
Range("A7") = Sheets("ExposureLog").Range("I2:I2") & (" - ") & Range("D2") 'set for all transactions
Range("I6") = Sheets("Table").Range("E68") 'set for construction contingency
Range("I7") = Sheets("Table").Range("E69") 'set for construction contingency
Range("I8") = Sheets("Table").Range("E70") 'set for construction contingency
Range("A9") = Range("E2") & (" ") & ("CONTINGENCY TRANSACTIONS") 'set for all transactions - may need IF statement to add note that pending means open
End If
End Sub